1

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?

1 Answer 1

7

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");
}
Sign up to request clarification or add additional context in comments.

2 Comments

When User.Identity will be set? In my current code, I just call "FormsAuthentication.SetAuthCookie(someusernumber, false)", will this method set User.Identity?
Yes it will because SetAuthCookie authenticates the user. You may have to reload the page after setting the cookie. A check for authentication after SetAuthCookie will return true.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.