简体   繁体   English

asp.net表单身份验证重定向问题

[英]asp.net forms authentication redirect problem

The default document feature is turned off in IIS and here's the situation... 在IIS中关闭默认文档功能,这是情况......

My start page for my project say is A.aspx. 我项目的起始页面是A.aspx。 I run the project and sure enough, A.aspx appears in the url of the browser. 我运行该项目,果然,A.aspx出现在浏览器的url中。 Like it should though, A.aspx finds no user logged in and redirects to Login.aspx like it should. 尽管如此,A.aspx发现没有用户登录并重定向到Login.aspx。

A.aspx: A.aspx:

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

The login.aspx shows up BUT when the user Logs in, the code: 当用户登录时,login.aspx显示BUT,代码:

FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, true); FormsAuthentication.RedirectFromLoginPage(txtUserName.Text,true);

always redirects to "Default.aspx" and not "A.aspx" 总是重定向到“Default.aspx”而不是“A.aspx”

I've examined FormsAuthentication.GetRedirectUrl and sure enough it returns "Default.aspx" 我检查了FormsAuthentication.GetRedirectUrl,果然它返回“Default.aspx”

I'm stumped???? 我难倒了????

In web.config you could set the default page using the defaultUrl attribute: web.config您可以使用defaultUrl属性设置默认页面

<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. 如果您正在使用FormsAuthentication,则应在web.config中定义您的设置。 It sounds like you have a default setting in the web.config for DefaultUrl. 听起来你在DefaultUrl的web.config中有一个默认设置。 You shouldn't need the session redirect though. 您不应该需要会话重定向。 FormsAuthentication should perform this for you. FormsAuthentication应该为您执行此操作。 It doesn't hurt to check the session and force a SignOut() if you don't find it, but FormsAuthentication should perform this redirect. 如果您没有找到会话并强制使用SignOut(),则不会有任何损害,但FormsAuthentication应执行此重定向。

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. 根据我的理解,当用户被重定向到您的登录屏幕时,表单身份验证机制会将用户最初访问的页面的URL添加到他们用户尝试访问的登录URL。 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. 例如,如果您有一个登录页面:http; // bob / login.aspx,并且用户试图访问http; // bob / showmethemoney.aspx,那么它们将被重定向到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. 因此,如果您在用户登录后使用ReturnUrl重定向用户,则用户将始终返回到他们最初尝试访问的资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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