internet-explorer - 302 登录重定向后 IE 删除的 URL 片段
问题描述
我们在应用程序中使用SiteMinder身份验证。
如果应用程序用户尝试https://ourapp.com/myapp/#/pending/requests
通过直接 URL 或通过书签 URL 导航到我们应用程序中的特定页面,SiteMinder
将重定向到login page
通过 302 重定向,类似于http://ourapp.com/login?redirect=https%3A%2F%2Fourapp.com%2Fmyapp%2F#/pending/requests
要求用户在登录表单中输入凭据。成功认证后,用户应该被重定向到我们的应用程序并登陆请求的页面(/pending/requests
)。
它在Chrome
和中工作得非常好Firefox
。当涉及到 IE 时,它会登陆https://ourapp.com/myapp/#/home
(默认登陆页面)而不是https://ourapp.com/myapp/#/pending/requests
.
我尝试google search results
了我们的应用程序代码中提供的各种解决方案,例如,
- 删除
<base>
标签index.html
- 在页面顶部添加以下代码行
// setting location back
window.location = window.location;
// setting location hash back
window.location.hash = window.location.hash;
- 与上述类似的其他解决方案很少
虽然这个问答非常有道理,
我还想preserve the URL hash fragment in IE even it's 3xx redirect
满足我的要求……!?
解决方案
回答我自己的问题
我发现在成功验证后,SiteMinder
正在302 redirection
使用名称类似于value
/myapp/
. 下面的示例表格without hash fragment
redirect
由于redirect
隐藏变量值只包含/myapp/
不包含散列片段并且它是 302 重定向,因此即使在进入我们的应用程序之前,IE 也会自动删除散列片段,并且无论我们在应用程序代码中尝试的任何解决方案都没有奏效。
IE 仅重定向到/myapp/
,它正在登陆我们应用程序的默认主页https://ourapp.com/myapp/#/home
。
浪费了将近一天的时间来弄清楚这种行为。
解决方案是:
通过附加现有值更改了登录表单隐藏变量 ( redirect
)的值以保存散列片段。window.location.hash
类似于下面的代码
$(function () {
var $redirect = $('input[name="redirect"]');
$redirect.val($redirect.val() + window.location.hash);
});
在此更改之后,redirect
隐藏变量将用户请求的 URL 值存储为/myapp/#/pending/requests
并将SiteMinder
其重定向到/myapp/#/pending/requests
IE。
上述解决方案在所有三种浏览器中都运行良好Chrome, Firefox and IE
。
感谢@AlexFord 对此问题的详细解释并提供了解决方案。
推荐阅读
- boto3 - 使用 boto3 从 python 代码执行 Athena Query 显示错误“botocore.errorfactory.InvalidRequestException”
- html - CSS将html标签样式放在一个类中
- css - 在 pdf 中让交替行成为不同的颜色
- c++ - gtkmm:如何在没有构建器的情况下创建弹出菜单?
- java - 为 IntelliJ Cassandra 数据库查看器设置时区
- .net - 如何将 Json 对象转换为 C# 类对象
- javascript - 如何根据 div 上的类对 HTML 内容进行排序
- c# - 仅在 .cshtml 页面(剃刀)中呈现 html 标记(链接)
- netbeans - 如何在 Windows 10 上安装 Netbeans 10
- xamarin - 更改导航页栏颜色和标题颜色