End-user can copy a URL of a view in my website then paste it onto the browser's address bar and hit enter to navigate to it. And I have a problem if that URL contains more than one question mark ?.
For example, users can enter this URL: https://mysite.local/testsite/NavigateToView.aspx?navigateURL=https://mysite.local/testsite/myview.aspx?viewID=A123&serviceID=B321
When the server receives this request, it does not understand the URL because the .NET framework allows only one question mark in a URL. I already found a solution to fix this one, which I need to encode the ReturnUrl's value and my server can understand the given URL.
But, I am facing a new scenario that when users copy and paste onto the address bar then hit enter to navigate to it, I am expecting the client should catch that event to modify the recently entered URL before the request sent to the server.
I tried this snippet code, but I cannot get the URL from the address bar properly.
My scenario:
- Chrome is currently showing a view of my website
https://mysite.local/testsite/home.aspx - Then, I copy and paste the above URL then hit enter
https://mysite.local/testsite/NavigateToView.aspx?navigateURL=https://mysite.local/testsite/myview.aspx?viewID=A123&serviceID=B321 - In Chrome developer, I can catch the change in the
beforeunloadevent, and please note that this newly entered URL is updated on the address bar successfully. Butwindow.location.href, at this time, is still pointing to the previous URLhttps://mysite.local/testsite/home.aspx
window.addEventListener('beforeunload', function (e) {
var pathname = window.location.href;
//pathname = https://mysite.local/testsite/home.aspx
});Is there a way that can solve my case? Thanks!
Aucun commentaire:
Enregistrer un commentaire