可以为不同的ASP.NET MVC3区域使用不同的登录URL吗?
我在每个区域的视图部分看到一个web.config,我已经尝试过:
<authentication mode="Forms"> <forms loginUrl="~/Administration/Account/logon" timeout="2880" /> </authentication>
但它不能奏效。
干杯。
解决方法
我不知道.NET处理这个,但你可以创建一个自定义的
AuthorizationAttribute
public class CustomAuthorization : AuthorizeAttribute { public string Url { get; set; } public override void OnAuthorization(AuthorizationContext filterContext) { if (!filterContext.HttpContext.User.Identity.IsAuthenticated) { filterContext.HttpContext.Response.Redirect(Url); } base.OnAuthorization(filterContext); } }
添加到您的控制器/操作
[CustomAuthorization(Url="/Area/Login")] public class HomeController { //... }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。