Yes. The browser allows "# / tasks / XYZ123" and requests a page without this hash. Although the hash itself appears on the login page - it works again in the browser. The hash is not sent to the server.
So, when does the browser load the login page with? ReturnUrl =% 2f # / tasks / XYZ123, we can rewrite the action of the form and encode the hash.
If the form looks like this:
<form action="/Home/Login" method="post" > ... </form>
The javascript code should look like this:
<script src="~/js/jquery.js"></script> <script type="text/javascript"> $(function() { var search = $(location).attr('search') || ''; var hash = $(location).attr('hash') || ''; if (hash.length === 0) { if (window.history.pushState) { window.history.pushState('login', 'Login', '/Home/Login'); } } else if (search === '?ReturnUrl=%2f') { $('form').attr('action', '/Home/Login' + search + encodeURIComponent(hash) ); } }); </script>
The part with window.history.pushState is required for the following:
If the hash is missing, then for SPA its URL (rather) will be:
http://hostname.com/Home/Login?ReturnUrl=%2f
so here we are trying to replace the URL (without reloading the page) with a more accurate
http:
source share