ASP Login Control - Checking login status

Jordan Foreman picture Jordan Foreman · Jun 17, 2011 · Viewed 9.7k times · Source

I want to use my code behind (C#) to check and see if a user is logged in or not on page load. I assume this is really basic, but I'm still new to .net

This is basically what I want:

if(loggedIn == true){ do something }

Answer

Tim B James picture Tim B James · Jun 17, 2011

If you are using the built in .net Forms Authentication, then you can use the following

if ( HttpContext.Current.User.Identity.IsAuthenticated){
     do something
}

Make sure you have your settings in the web.config set up for using FormsAuthentication