2012-05-30 52 views
4

我正在学习如何使用随.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; 

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

回答

2

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

您可以启用“匿名访问”在IIS中与用户帐户

从CodeProject绑定匿名身份:
如果你运行该代码在IIS6下匿名模式下,你将得不到任何细节如下所示。 enter image description here

看看在asp.net认证和authorizaion下面的文章:
http://www.codeproject.com/Articles/98950/ASP-NET-authentication-and-authorization

在IIS7您可以导航到安全>>认证如下:

enter image description here

enter image description here

+0

这就是IIS6 se不是吗?它很可能@Tom使用II7。 – abatishchev

+0

添加了2张图片 –