具有不同的登录页面不同的ASP.NET MVC 3区 [英] Having different login pages for different ASP.NET MVC 3 areas
本文介绍了具有不同的登录页面不同的ASP.NET MVC 3区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以有不同的ASP.NET MVC3地区不同的登录网址是什么?
Can I have different login URL for different ASP .NET MVC3 areas?
例如。我想有不同的登录页面,管理员和数据录入员。
e.g. I would like to have different login page for Administrator and Data entry operators.
我看到每个区域的观点部分的web.config中,我已经尝试过这样做的:
I see a web.config in each area's view portion and I have tried doing:
<authentication mode="Forms">
<forms loginUrl="~/Administration/Account/LogOn" timeout="2880" />
</authentication>
但它没有发挥好。
but it does not play well.
干杯。
推荐答案
我不知道.NET处理这个给你,但你可以创建一个自定义的<一个href="http://msdn.microsoft.com/en-us/library/ff422833%28v=VS.91%29.aspx">AuthorizationAttribute
I'm not aware of .NET handling this for you but you could create a custom 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);
}
}
这是添加到您的控制器/动作
An add that to your controllers/actions
[CustomAuthorization(Url="/Area/Login")]
public class HomeController {
//...
}
这篇关于具有不同的登录页面不同的ASP.NET MVC 3区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文