首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >err_too_many_redirects in HandleUnauthorizedRequest

err_too_many_redirects in HandleUnauthorizedRequest
EN

Stack Overflow用户
提问于 2017-05-02 10:17:54
回答 1查看 4.4K关注 0票数 0

我在MVC中工作。我搞错了

err_too_many_redirects

在……里面

HandleUnauthorizedRequest

代码语言:javascript
复制
public class AuthCheckService : AuthorizeAttribute
{
    protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
    {
        if (filterContext.RequestContext.HttpContext.Request.IsAjaxRequest())
        {
            //Ajax request doesn't return to login page, it just returns 403 error.
            filterContext.HttpContext.Response.Clear();
            filterContext.HttpContext.Response.StatusCode = 501;
            throw new ModelStateException("Your Session has expired- Please login again!");
        }
        else
        {
            base.HandleUnauthorizedRequest(filterContext);
            //filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { action = "Login", controller = "Account" }));
        }

    }
}

请让我知道我哪里出错了?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-11 09:53:14

我在web配置文件中测试时犯了一个愚蠢的错误:

代码语言:javascript
复制
 <sessionState timeout="2" cookieName="OnshoreMaintSSID" regenerateExpiredSessionId="true" />
<authentication mode="Forms">
  <forms loginUrl="Account/Login" timeout="1" name=".Onshore" requireSSL="false" />
</authentication>
<pages>

正如您在上面看到的,会话状态超时大于窗体身份验证超时。这就是问题的根源。

解决方案:

代码语言:javascript
复制
 <sessionState timeout="1" cookieName="OnshoreMaintSSID" regenerateExpiredSessionId="true" />
<authentication mode="Forms">
  <forms loginUrl="Account/Login" timeout="2" name=".Onshore" requireSSL="false" />
</authentication>
<pages>

希望这会对其他人有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43735421

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档