ASP.Net自定义授权属性错误地重定向到IE中的登录页面

时间:2016-04-13 15:41:43

标签: asp.net asp.net-mvc forms-authentication

当用户没有正确的角色访问页面时,我想显示自定义访问被拒绝页面,因此我创建了自定义AuthorizeAttribute。这运作良好,但我们遇到了一个奇怪的问题。我们的一个页面使用默认的索引操作,这个操作会在用户使用IE时将用户重定向到登录页面。这似乎只发生在IE中,只有在操作默认时才会发生。意思是,带/ Area / Controller / Index的URL工作正常,但如果你只是放入/ Area / Controller它会重定向到登录页面。(在web.config中的forms标签中指定)另一个奇怪的是,这发生了始终处于产品环境中,但不是在测试环境中。 web.config标签中没有任何特定于页面的内容,并且在该区域的Route配置中没有任何有趣的内容。(下面)

任何人都知道要调查的任何错误或其他内容吗?(或者可能解释它的默认操作有些奇怪)

 context.MapRoute(
                "TicketEntry_default",
                "TicketEntry/{controller}/{action}/{id}",
                new { action = "Index", id = UrlParameter.Optional }
            );



  Here is the Authorize attribute:
public class AccessDeniedAuthorizeAttribute : AuthorizeAttribute
    {
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            base.OnAuthorization(filterContext);
            if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
            {
                filterContext.Result = new RedirectResult("/Login");
                return;
            }



if (filterContext.Result is HttpUnauthorizedResult)
        {
            filterContext.Result = new RedirectResult(filterContext.HttpContext.Request.IsAjaxRequest() ? "/Login/Login/AccessDeniedAjax" : "/Login/Login/AccessDenied");
        }
    }
}

0 个答案:

没有答案
相关问题