gpt4 book ai didi

asp.net-mvc - 使用 ASP.NET MVC 和表单例份验证的不同 URL 的不同登录 URL

转载 作者:行者123 更新时间:2023-12-04 02:20:08 24 4
gpt4 key购买 nike

我有一个 ASP.NET MVC 项目,我想为网站的不同区域使用不同的 LoginUrl。根据站点的区域,输入不同类型的凭据。
http://host.com/widget/home应该将用户重定向到 http://host.com/widget/logon .
http://host.com/admin/home应该将用户重定向到 http://host.com/admin/logon .

到目前为止,我想出的最佳解决方案是在 web.config 中使用 Forms Auth loginUrl="~/Account/Logon":

   <authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880"/>
</authentication>

在帐户的 Controller 中:
public ActionResult LogOn()
{
//redirect depending on the returnUrl?
string returnUrl = ControllerContext.Controller.ValueProvider["ReturnUrl"].AttemptedValue;
if (returnUrl.StartsWith("/widget"))
{
return Redirect(string.Format("/widget/Logon?ReturnUrl={0}", returnUrl));
}
if (returnUrl.StartsWith("/admin"))
{
return Redirect(string.Format("/admin/Logon?ReturnUrl={0}", returnUrl));
}
return View();
}

有一个更好的方法吗?

最佳答案

我在我的 stackoverflow 问题 How to redirect to a dynamic login URL in ASP.NET MVC 中提出并回答了这个问题.

关于asp.net-mvc - 使用 ASP.NET MVC 和表单例份验证的不同 URL 的不同登录 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1327883/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com