开发者

Does .Net Forms Authentication Require Session?

开发者 https://www.devze.com 2023-02-02 19:02 出处:网络
We are having a discussion about how forms a开发者_开发问答uthentication really works. Is all information that identifies the user as being logged in stored in the cookie, or is some information stor

We are having a discussion about how forms a开发者_开发问答uthentication really works.

Is all information that identifies the user as being logged in stored in the cookie, or is some information stored in the session?


Information about the user being authenticated is stored in the FormsAuthenticationTicket in a cookie, by default named .ASPXAUTH.

Information about a user's session is separate from information about authentication. The identifier for session can be stored in a cookie (a different cookie from the authentication cookie) or, as Henk has pointed out, in a cookieless session i.e. as part of the URL.

The problem with storing some information about authentication in a user's session is that session is not available until some time after the authentication event (5 events later IIRC) in the processing pipeline, in PostAcquireRequestState. This means you wouldn't have access to the authentication data in session until after authentication!

It's possible to store data in session and to overwrite the IIdentity and IPrincipal with that data, but this does means that the user identity will have some data for the events before session is available and different data for the events after session is available, which may or may not be a problem. Furthermore, you'll probably want to cryptographically secure that data in session in some way.

To answer your title question, forms authentication does not require session; they are distinct entities required for different purposes.


For how Forms Authentication works, you can check out the below links:

  • Explained: Forms Authentication in ASP.NET 2.0
  • Understanding the Forms Authentication Ticket and Cookie

Forms Authentication works in web farm scenarios where the server handling a request from a Forms authenticated user may be different than the server that actually authenticated the user and issued the Forms authentication ticket and the cookie unless cookieless forms authentication is configured. To make this work, according to Web Farm Scenario section of the first link:

To address this issue, the validationKey and decryptionKey values must be identical on all computers in the Web farm. For more information about configuring the machineKey element, see How To: Configure MachineKey in ASP.NET 2.0.

which suggests that the Forms Authentication does not store anything in ASP.NET session. Otherwise, you would need to set up some form of an out-of-process session management in-place as well.

I also had a sample Forms Authentication application on hand and wanted to prove this quickly. After getting authenticated via Forms Authentication and landing on the home page, I restarted the application pool that the sample application was running in which should kill the user session. I then clicked on one of the links requiring authentication on the home page and was able to go to that link without getting redirected to the login page.

0

精彩评论

暂无评论...
验证码 换一张
取 消