And just to add a little to the above:
The GUID saved in the cookie is only stored in that cookie when you are using forms authentication. With true, unknown and anonymous (internet) users, ASP.NET hands out this cookie to keep track of a user. For each anonymous user, a record in the aspnet_Users (but not aspnet_Membership) is created.
When you are using Windows Authentication, you are always a known user, so you are never anonymous. This means you don't get a cookie with your ID. (There is no need to; you can be tracked with your Windows name). But, you do get a record in the aspnet_Users table in the format MachineName\UserName. This user is then used to hook it up to other data, including the aspnet_Profiles table.
So, in short, when you are using Windows authentication, you are always logged in by default. This is NOT because you have a record in aspnet_Users, but because you are an authenticated Windows user. In fact, the record in aspnet_Users is put there because you *are* an authenticated user.
To see what I mean and to clarify things, try this:
1. Create a brand new web site in Visual Web Developer. Accept all defaults.
2. Add the following to the web.config under system.web:
Code:
<anonymousIdentification enabled="true"/>
<profile enabled="true">
<properties>
<add name="MemberName"/>
<add name="Name"/>
<add name="Address"/>
<add name="City"/>
<add name="County"/>
<add name="PostCode"/>
<add name="Country"/>
<add name="Mailings" type="System.Boolean"/>
<add name="Email"/>
<add name="Theme"/>
</properties>
</profile>
3. Add the following to the Default.aspx.
vb file:
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Profile.MemberName = "Your Name"
End Sub
4. Save everything and hit F5.
Default.aspx loads and the profile is saved.
Close your browser and look at the database that has been created in App_Data. You'll find a record in the following tables:
1. aspnet_Users: MachineName\UserName
This is an ASP.NET Services user mapped to a Windows account. This user is used for the Profiles
2. aspnet_Profiles
A profiles record is stored in this table, with the user ID from [1]
Additionally, there is no ASPXANONYMOUS cookie. The profile is tracked through your Windows account name and not through a cookie.
If you want, start all over (delete the entire site) and follow all the steps. However, right before you hit F5, change this:
<authentication mode="Windows"/>
to
<authentication mode="Forms"/>
You'll see similar behavior. However, this time round, your user name in aspnet_Users is a GUID, and you'll have a cookie in your browser that links your browser to the user in aspnet_Users.
Hope this clarifies things.
For everyone who wants to learn more about this (in fact, get to the bottom of it), I can wholeheartedly suggest the book "Professional ASP.NET 2.0 Security, Membership, and Role Management" by "Stefan Schackow". It's without a doubt the best book on the subject. You can find the book here:
http://www.wrox.com/WileyCDA/WroxTit...764596985.html
This will be my last post for a while, so I won't be able to answer any follow up questions.
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of
ASP.NET 2.0 Instant Results and
Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.