HTML 是这样的:
<asp:Login ID="LoginUser" runat="server" EnableViewState="false" RenderOuterTable="false" OnLoggedIn="LoginUser_LoggedIn"
OnLoginError="LoginUser_LoginError">
</asp:Login>
上
LoginUser_LoggedIn
事件我正在设置目标 URL,如:LoginUser.DestinationPageUrl = "~/mycustompage.aspx";
FormsAuthentication.RedirectFromLoginPage(LoginUser.UserName, true);
这里当没有
ReturnUrl
在页面 URL 中,它会重定向到“~/mycustompage.aspx”页面,但如果 URL 中指定了任何 ReturnUrl,则它会重定向到 ReturnUrl 页面。无论 ReturnUrl 是否存在,我总是想重定向到“~/mycustompage.aspx”页面。如何实现这一目标?
非常感谢提前!
最佳答案
DestinationPageUrl
是登录后的默认目标页面。?ReturnUrl
强于DestinationPageUrl
所以,如果设置了它就赢了。Response.Redirect
在 LoginUser_LoggedIn
强于ReturnUrl
所以,如果你想覆盖 ReturnUrl
您必须使用此代码:
void LoginUser_LoggedIn(Object sender, EventArgs e)
{
Response.Redirect("~/mycustompage.aspx");
....
}
DestinationPageUrl
应该在aspx页面中设置 <asp:Login DestinationPageUrl="~/mycustompage.aspx" ... />
或在
Page_Load
事件正常工作。void PageLoad(Object sender, EventArgs e)
{
LoginUser.DestinationPageUrl = "~/mycustompage.aspx";
....
}
如果您必须在登录后更改目标页面(例如,如果页面根据用户或用户的角色而变化),您必须使用
Server.trasfer()
矿石 Response.Redirect()
.void LoginUser_LoggedIn(Object sender, EventArgs e)
{
Response.Redirect("~/mycustompage.aspx");
....
}
关于ASP.NET LoginUser.DestinationPageUrl 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20370416/