繁体   English   中英

身份验证后从URL重定向ASP.Net

[英]ASP.Net re-direct from URL after authentication

我有一个Web应用程序,需要用户进行身份验证才能查看某些页面。

通过重定向到Login.aspx,在web.config中强制进行身份验证

当用户位于Login.aspx页上时,URL的格式如下:

http:// localhost:51101 / Login.aspx?ReturnUrl =%2fSupport.aspx

用户授权后,我希望ASP.Net将用户重定向到Support.aspx页,但这不会发生。

Support.aspx并不是唯一需要身份验证的页面,因此我无法在代码隐藏文件中进行重定向。

是否有我遗漏的web.config设置?

谢谢

编辑:

基本身份验证逻辑

            if (!Membership.ValidateUser(user, password))
            {
                errorId.Text = "Incorrect username or password";
            }
            else
            {
                FormsAuthentication.SetAuthCookie(user, true);  
                // I can add a re-direct here, but it won't do the job since there are multiple pages that require authentication
            }

您正在使用表单身份验证吗? 如果是这样,您将需要致电

FormsAuthentication.RedirectFromLoginPage()

Login.aspx中的方法

参考

我认为没有ASP.NET可以为您处理此问题的方法。 您可能必须在Global.asax Session_Start()中手动在查询字符串中查找“ returnUrl”,并在用户登录后重定向到该值。

编辑:我错了。 感谢John Pick纠正我。

暂无
暂无

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

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