在 Websphere 中将基于表单的身份验证与 AngularJS 一起使用时出现奇怪的行为

Weird behavior when using form based authentication with AngularJS in Websphere

我正在使用基于表单的身份验证进行 AngularJS 项目,有时会出现意外行为 我无法追踪。

Websphere 8.0.0.10 上的应用程序运行,会话管理由cookie 完成。

所需的工作流程如下:

这是期望的行为,但有时它的行为会有所不同。我进入申请后 然后关闭浏览器,然后再次打开它会转到 $routerProvider 定义的 '/page', 你可以在下面看到这段代码:

$routeProvider.when('/pages', {
        templateUrl: 'pages.html',
        controller: 'pagesCtrl'
     });

      $routeProvider.when('/page', {
          templateUrl: 'page.html',
        controller: 'pageCtrl'
      })

    .otherwise({redirectTo: '/page'});

它转到 '/page' 但应用程序不工作,抛出各种异常,它无法启动这个或那个模块 即使我手动删除了 cookie,或者即使我在 Chrome 中打开应用程序 incognito window 当会话应该过期并且 Websphere 应该将它重定向到 login.html。 只有当我再次刷新它时,它才会转到 login.html

如果我理解正确的话,它是由浏览器和应用程序的一些模块部分缓存的 从缓存加载,甚至更多,当我在打开开发人员控制台并禁用缓存的情况下加载应用程序时 它运行完美,但当控制台关闭时它不起作用。

我试图通过将以下代码添加到我的 index.html 来禁用缓存,但它没有帮助:

    <meta http-equiv="cache-control" content="max-age=0" />
    <meta http-equiv="cache-control" content="no-cache" />
    <meta http-equiv="expires" content="0" />
    <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
    <meta http-equiv="pragma" content="no-cache" />

提前谢谢你。

问题已解决。我在以下几行中使用了@WebFilter:

HttpServletResponse response = (HttpServletResponse) res;
response.addHeader("Pragma", "no-cache");
response.addHeader("Cache-Control", "no-cache");
response.addHeader("Cache-Control", "no-store");
response.addHeader("Cache-Control", "must-revalidate");
response.addHeader("Expires", "Tue, 01 Jan 1980 1:00:00 GMT");