R – Asp.Net Forms Authentication browsing to Login page again after a successful Login

asp.netasp.net-2.0asp.net-membership

I have my forms authentication system working.

I found an odd behavior such that after successful Login; I was asked to Login again, if I browse to Login page from default page.

I was assuming that it should redirect me to default page since I am already authenticated.

Here's Web.config element I used:

<authentication mode="Forms">
 <forms loginUrl="login.aspx" defaultUrl="default.aspx" />            
</authentication>
<authorization> 
 <deny users="?"/>
</authorization>

Best Answer

This is the normal behavior. The login page is a regular ASP.NET webform. It will display whatever is in it.

You could add code to the Form_Load event of the login page to check if the user is already authenticated. Then, you could redirect them to the default by calling the FormsAuthentication.RedirectFromLoginPage method if that's what you are after.

Related Topic