微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 如何检测匿名配置文件

我正在学习如何使用.NET中的Membership和Role附带的Profile.但是,我不确定链的顶部设置值的位置:

//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的关系感到困惑.获取/设置用户进行身份验证或匿名的正确方法是哪一种?我的目标是让匿名用户和经过身份验证的用户都能拥有个人资料.

解决方法

res1和res2不同,因为它的值取决于IIS配置中的设置.

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

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中,您可以导航到Security>>认证如下:

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐