ASP.NET Forms Authentication - How to Know if User Has Previously Been Authenticated

D

David Krussow

The 2nd parameter of the
[System.Web.Security.FormsAuthentication.RedirectFromLoginPage(string,
bool)] method controls whether a persistent cookie is created - so that
ASP.NET can "know" if the current user has been previously authenticated
(during previous browser sessions).

My question: How can code I write elsewhere in the application retrieve that
cookie - or otherwise "know" if the current user has been authenticated? My
intent is to have some pages in the application that do not require
authentication in order to be viewed, but do display additional content only
for users who have been authenticated (during the curren session or a
previous browser session). That logic would need to somehow look for the
cookie that was created during authentication or verify that no such cookie
exists. How do I do that?

Thanks
 
J

John Saunders

David Krussow said:
The 2nd parameter of the
[System.Web.Security.FormsAuthentication.RedirectFromLoginPage(string,
bool)] method controls whether a persistent cookie is created - so that
ASP.NET can "know" if the current user has been previously authenticated
(during previous browser sessions).

My question: How can code I write elsewhere in the application retrieve that
cookie - or otherwise "know" if the current user has been authenticated? My
intent is to have some pages in the application that do not require
authentication in order to be viewed, but do display additional content only
for users who have been authenticated (during the curren session or a
previous browser session). That logic would need to somehow look for the
cookie that was created during authentication or verify that no such cookie
exists. How do I do that?

You don't need to do anything with the cookie.

Request.IsAuthenticated will tell you if the current request is
authenticated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top