开发者

Internet Explorer, Safari, Opera removes hash value from returnUrl

开发者 https://www.devze.com 2023-04-11 23:43 出处:网络
I want 开发者_如何学编程to keep hash value in returnURL when user is sent to LogOn controller, but IE7-9/Safari/Opera removes it.

I want 开发者_如何学编程to keep hash value in returnURL when user is sent to LogOn controller, but IE7-9/Safari/Opera removes it.

For example, I try this URL

http://localhost:18314/#&t={DA3DB617-F9A3-4668-93E6-BBB2E37B928F}

User is not authorized and sent to LogOn controller. I get just this in IE7-9, Safari, Opera:

http://localhost:18314/Login/LogOn?ReturnUrl=%2f

But in FireFox and Chrome:

http://localhost:18314/Login/LogOn?ReturnUrl=%2f#&t={DA3DB617-F9A3-4668-93E6-BBB2E37B928F}

Why and how to fix?!

Thanks! :-)


You have to escape the hash using %23

so this:

?ReturnUrl=%2fFolder1#Hash

becomes:

?ReturnUrl=%2fFolder1%23Hash

Tested in IE9.


Everything after hash is not sent to server. Good thing is that you can share cookies between your client code and server code. I had same problem and ended up to add my hash value into one cookie

// Note that I am using 3rd part library for cookies
<script src="~/scripts/jquery-1.10.2.js"></script>
<script src="~/scripts/jquery.cookie.js"></script>
<script type="text/javascript">
    $(function () {
        var cookieKey = "MYHASH";
        $.removeCookie(cookieKey);
        $.cookie(cookieKey, window.location.hash, { expires: 7, path: '/' });
    })
</script>

Later, when I am handling connected user in my controller value Request.Cookies["MYHASH"]; will give me hash value so I can redirect user. I am sure with some modifications this can help you solve the problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号