我想知道是否有人知道在您成功登录后覆盖网页所在位置的正确/最佳实践方式。
我试过了:
protected void Login1_LoggedIn(object sender, EventArgs e)
{
if (Roles.IsUserInRole(Login1.UserName, "Other"))
{
Response.Redirect("/User/");
}
else if (Roles.IsUserInRole(Login1.UserName, "Administrator"))
{
Response.Redirect("/Admin/");
}
}
有没有人有任何其他建议?
答案 0 :(得分:3)
您可以将以下元素添加到Web.config中。所以它只能在一个地方设置:
<loginRedirectByRole>
<roleRedirects>
<add role="Administrator" url="~/Admin/Page.aspx" />
<add role="User" url="~/User/Page.aspx" />
</roleRedirects>
</loginRedirectByRole>
你仍然需要在代码中进行重定向 - 查看完整的Article
答案 1 :(得分:0)
我所做的是将它们发送到一个页面,该页面将重定向到Init(Page_Init)上的正确位置
答案 2 :(得分:0)
HttpContext.Current.Response.RedirectLocation
“获取或设置HTTP标头'位置'中的重定向位置”
这最初是由查询字符串中的“ReturnUrl”设置的。