views:

206

answers:

1

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>
+3  A: 

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.

Jose Basilio
Suppose I have a photo.aspx page. Once login I go to photo.aspx page, System will load the photo page only when I am authenticated.(I don't write extra code to make this happen) Why I should not expect the same behavior on login page. i.e. Load the page if I am authenticated (redirect to default) otherwise show the login form.
TigerAmit
@TigerAmit, ok, let me give it a shot... The login page redirects you to the page you were trying to access when you were redirected to it (the login page). If you were not redirected there, I has no idea where to send you, so it just posts back to itself. Make sense? In other words, if you browse to login and login, then login thinks you wanted to access login, and coincidentally you are already at login, so login has nothing to do except log you in. ;-)
Sky Sanders