【问题标题】:Internet Explorer not redirecting to unauthorized page on logoutInternet Explorer 在注销时未重定向到未经授权的页面
【发布时间】:2014-04-07 15:55:42
【问题描述】:

我们有一个带有 MVC 后端的 Angular JS 应用程序,该应用程序使用 WIF 对使用 Azure ASC 的用户进行身份验证。 MVC 控制器具有[Authorize] 属性,因此当未经身份验证的用户尝试访问需要身份验证的页面时,他们会收到 401 错误。

所以流程如下:

  1. 尝试访问Home/Index
  2. 收到 401 错误
  3. Angular httpInterceptor 接收 401 并使用 $location.path("/unauthorized"); 重定向到未经授权的(登录)页面;
  4. 用户单击登录按钮并被重定向到 Azure ACS 进行身份验证。
  5. 身份验证成功后,用户将使用身份验证令牌返回站点,并且可以访问受保护的资源。

有角度的httpInterceptor:

      // On response failture
        responseError: function (rejection)
        {
            // console.log(rejection); // Contains the data about the error.
            if (rejection.status == 401)
            {
                $location.path("/unauthorized");
                return $q.when(rejection);
            }
            // Return the promise rejection.
            return $q.reject(rejection);
        }

当我第一次加载页面时,所有浏览器都按预期运行。

问题发生在我注销时。除了 IE 之外的所有浏览器都会出现以下情况

  1. 通过重定向到注销 URL 执行单点注销。
  2. 退出后被重定向回默认页面,但由于我现在没有身份验证令牌,我收到 401
  3. 我被重定向到未经授权的(登录)页面

但是,当使用 IE 时,上述第 2 步中不会出现 401。因此会发生注销,但会加载默认页面。没有加载任何角度脚本,因为我在以下 razor 语句中加载了所有角度控制器、服务和指令:

@if (User.Identity.IsAuthenticated)
{
    //load angular files here
}

当我查看 fiddler 发生的事情时,我可以看到 401 不会在 IE 中发生 http://i.imgur.com/Of53mEY.png

但它适用于其他浏览器:

http://i.imgur.com/g1GmVw3.png

为什么 401 不像其他浏览器那样在 IE 上发生?

【问题讨论】:

    标签: asp.net-mvc angularjs authentication wif


    【解决方案1】:

    我能够通过将一些角度文件移到以下语句之外来解决问题。

    @if (User.Identity.IsAuthenticated)
    {
        //load angular files here
    }
    

    不知道为什么 IE 在重定向之前需要这些,而不是其他浏览器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多