简体   繁体   中英

asp.net forms authentication redirect problem

The default document feature is turned off in IIS and here's the situation...

My start page for my project say is A.aspx. I run the project and sure enough, A.aspx appears in the url of the browser. Like it should though, A.aspx finds no user logged in and redirects to Login.aspx like it should.

A.aspx:

    if (Session["UserStuff"] == null)
        Response.Redirect("~/Account/Login.aspx"); 

The login.aspx shows up BUT when the user Logs in, the code:

FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, true);

always redirects to "Default.aspx" and not "A.aspx"

I've examined FormsAuthentication.GetRedirectUrl and sure enough it returns "Default.aspx"

I'm stumped????

In web.config you could set the default page using the defaultUrl attribute:

<authentication mode="Forms">
    <forms 
       loginUrl="login.aspx" 
       defaultUrl="a.aspx"
       protection="All"  
       timeout="30" 
    />
</authentication>

If you're using FormsAuthentication, your settings should be defined in the web.config. It sounds like you have a default setting in the web.config for DefaultUrl. You shouldn't need the session redirect though. FormsAuthentication should perform this for you. It doesn't hurt to check the session and force a SignOut() if you don't find it, but FormsAuthentication should perform this redirect.

From my understanding, when the user is redirectoed to your login screen, the Forms Authentication mechanism will add the url of the page that the user was originally tring to access, to the login url that that they user tried to access. For example, if you had a login page: http;//bob/login.aspx, and a user tried to access http;//bob/showmethemoney.aspx, then they would get redirected to http;//bob/login.aspx?ReturnUrl=showmethemoney.aspx. So, if you use the ReturnUrl to redirect the user after the user logs in, the user will always be returned to the resource that they were originally trying to get to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM