C# – Forms authentication issue

asp.netcforms-authenticationiis-7visual-studio-2008

I am using VSTS 2008 + C# + .Net 3.5 + ASP.Net + IIS 7.0. And I am implementing Forms authentication.

I want to know in Forms authentication, how to check whether a user is already authenticated or not?

Best Answer

You can use HttpContext.Current.User.Identity.IsAuthenticated to check whether they're authenticated. For example

if(User.Identity.IsAuthenticated)
{
Response.Write("Logged in already");
}
else
{
Response.Write("Please log in");
}