Reputation: 85775
I am still a bit confused about something about FormsAuthenticationTicket
and the actual cookie container.
What does DateExpiration
in FormsAuthenticationTicket()
refer to? Is that when the cookie dies? Is that how long the user can stay logged in without any active actions (i.e. timeout)?
<forms loginUrl="~/Account/LogOn"
protection="All"
timeout="20160"
name="test"
path="/"
requireSSL="false"
slidingExpiration="false"
defaultUrl="default.aspx"
cookieless="UseDeviceProfile"
enableCrossAppRedirects="false" />
This is what is in my web config. Now, do any of these get set to the cookie automatically? For instance, can I grab from the name
field what I need to grab when making my cookie?
HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
But what about setting protection
(whatever that is), timeout
, slidingExpiration
, enableCrossAppRedirects
, cookieless
etc.? I don't see properties to set these. Are they automatically taken from the webconfig or what?
What is the difference between DateExpiration
set in the FormsAuthTicket
and the one you set for the cookie (authCookie.Expires
)?
Thanks
Upvotes: 1
Views: 1486
Reputation: 124726
It controls how long the user can access the site without reauthenticating.
UPDATE
This MSDN article has info on this subject. If protection is set to All in your web.config, then the ticket is encrypted using the algorithm specified on the machineKey element. The default is SHA1 and AES according to this article.
If you want to see an unencrypted ticket you can set protection="None" in your web.config, though you wouldn't normally want to do this in a production app.
You can also use a tool such as Lutz Reflector to examine the source of the FormsAuthentication and FormsAuthenticationTicket classes to understand more about how the ticket is generated.
Upvotes: 3