4

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

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

4

1 回答 1

2

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

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

来自 Codeproject:
如果您在 IIS6 中以匿名模式运行此代码,您将不会获得如下所示的详细信息。 在此处输入图像描述

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

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

在此处输入图像描述

在此处输入图像描述

于 2012-06-07T07:27:37.253 回答