Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference usage between Formsauthentication.SetAuthCookie and Session

I can't seem to find an answer to this seemingly simple question.

What is the difference between using the first or the later? Why would I use the first?

On MSDNAA I find the following regarding Formsauthentication.setCookie():

Creates an authentication ticket for the supplied user name and adds it to the cookies collection of the response, or to the URL if you are using cookieless authentication.

Regarding Session:

ASP.NET session state enables you to store and retrieve values for a user as the user navigates the different ASP.NET pages that make up a Web application. HTTP is a stateless protocol, meaning that your Web server treats each HTTP request for a page as an independent request; by default, the server retains no knowledge of variable values used during previous requests. As a result, building Web applications that need to maintain some cross-request state information (applications that implement shopping carts, data scrolling, and so on) can be a challenge. ASP.NET session state identifies requests received from the same browser during a limited period of time as a session, and provides the ability to persist variable values for the duration of that session.

I'm especially interested in why I'd use formsauthentication.SetAuthCookie when I use a session cookie to check if the user is correctly logged in. E.g.:

if(Session["LoggedIn"] != null) {
    ...Do something here that only logged in users are allowed to do...
} 
like image 733
reaper_unique Avatar asked Jan 04 '13 12:01

reaper_unique


1 Answers

It seems that I've found my answer on the asp.net site:

http://forums.asp.net/t/1587046.aspx/1#4012585

like image 51
reaper_unique Avatar answered Jan 03 '23 23:01

reaper_unique