I am learning how to use Profile that comes with Membership and Role in .NET. However, I am not sure where is the top of the chain to set the value:
//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.
And to get the value:
//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;
I am confused about the relations of auth/anonymous in each of them. Which one is the correct way to get/set user to be authenticated or anonymous? My goal here is to enable both anonymous users and authenticated users to have a profile.
The
res1
andres2
are different as its values depend on the settings in IIS config.You can enable the "Anonymous Access" in IIS to bind the anonymous identity with a User Account
Take a look at following article on asp.net authentication and authorizaion:
http://www.codeproject.com/Articles/98950/ASP-NET-authentication-and-authorization
In IIS7 you can navigate to Security >> Authentication as follows: