身份验证MVC3地区
问题描述:
我创造与地区一个MVC应用程序。 我需要对这些区域有不同的身份验证方法。身份验证MVC3地区
我通常使用的HttpModules进行身份验证,HTTP模块我检查,如果用户进行身份验证(我通常使用cookies)的,如果没有我重定向他。
所以,我对于验证整个应用程序的一个HttpModule,我要注册其他的HttpModule在该地区的认证。
我想:
- 使用在该地区文件夹中的web.config文件,列出的HttpModule那里。
- 在web.config文件中使用位置部分。
双方并没有为我工作的HttpModule从来没有得到所谓的。
- 如何为一个区域注册httpmodule。
- 我如何覆盖整个应用程序的httpmodule。
- 如果这是绕了什么是这样做的更好的方法错了。
感谢
答
你总是可以写,你重写AuthorizeCore定制AuthorizeAttribute。在这个功能中,你总是可以重定向到特定的登录名。在web.config中
定义public class CustomAuthorizationAttribute : AuthorizeAttribute
{
private string notifyUrl = string.Format("{0}{1}", GeneralHelper.BaseSiteUrl, "Login");
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
if (httpContext.User.Identity.IsAuthenticated)
{
// get userinformation
return true;
}
httpContext.Response.Redirect(NotifyUrl);
return false;
}
}
如果不包括重定向,它西港岛线被重定向loginurl