Internet Explorer, Safari, Opera removes hash value from returnUrl
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.
精彩评论