c# - 如何检测匿名个人资料

标签 c# asp.net .net asp.net-membership asp.net-profiles

我正在学习如何使用 .NET 中的成员资格和角色附带的配置文件。但是,我不确定链的顶部在哪里设置值:

//Q1. Does it mean I set auth manually when loading user, or create it if not already exists? 
//Or am I meant to get the isauth value from somewhere and pass it in?
var currentUserProfile = ProfileBase.Create(Membership.GetUser().UserName, isauth);
var anyUserProfile = ProfileBase.Create(strNewUser, isauth);
//isauth: true to indicate the user is authenticated;
//        false to indicate the user is anonymous.

并获取值:

//Q2. Are res1 and res2 below reflecting the same thing?
//Gets a value that indicates whether the user has been authenticated
bool res1 = HttpContext.Current.User.Identity.IsAuthenticated;
//Gets a value indicating whether the user profile is for an anonymous user
bool res2 = HttpContext.Current.Profile.IsAnonymous;

我对它们每个中的 auth/anonymous 关系感到困惑。哪一个是获取/设置用户进行身份验证或匿名的正确方法?我的目标是让匿名用户和经过身份验证的用户都拥有个人资料。

最佳答案

res1res2 是不同的,因为它的值取决于 IIS 配置中的设置。

您可以在 IIS 中启用“匿名访问”以将匿名身份与用户帐户绑定(bind)

From Codeproject:
if you run this code in IIS6 under anonymous mode you will get no details as shown below. enter image description here

请查看以下有关 asp.net 身份验证和授权的文章:
http://www.codeproject.com/Articles/98950/ASP-NET-authentication-and-authorization

在 IIS7 中,您可以导航到安全 >> 身份验证,如下所示:

enter image description here

enter image description here

关于c# - 如何检测匿名个人资料,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10815765/

相关文章:

c# - 在 C# 中使用 FileSystemWatcher 确定复制/写入进度

c# - 如何使信号器客户端避免表单例份验证?

c# - 如何使用继承/多态性将 JSON 字符串解析为 C# 对象?

asp.net - 在 .net 中获取 Paypal 帐户中的总余额

c# - 压缩 SQL Server 2005 查询结果?

asp.net - ASP.NET 3.5 中与 Request.RawUrl 属性相关的可能错误/问题

c# - WebAPI OData $格式到 xml

c# - 自托管webapi时如何设置http请求队列长度?

.net - .NET 跟踪中的 "switch"和 "filter"有什么区别?

.net - Windows 运行时 : Does it include a logging library?