Pass URL's with hash value for redirection [du

2019-05-10 20:49发布

问题:

Possible Duplicate:
How to get Url Hash (#) from server side

I'm having some trouble to get the hash value from a variable.

I'm using the default action in the AccountController

[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl) { ... }

but if I pass this link on:

http://localhost:1357/none/Account/LogOn?returnUrl=a/b/c#day-22

I can never catch the #day-22 value

below it's a breakpoint after the login:

I never get the hash value on the HttpContext.Request.Url object.

What can I do to forward the user to the correct URL with the hash part?

回答1:

You need to urlencode it.

Try: http://localhost:1357/none/Account/LogOn?returnUrl=a/b/c%23day-22



回答2:

This is not possible because the URL fragment (the bits after the #) is not sent from the browser to the server.



回答3:

Use HttpUtility.UrlEncode and HttpUtility.UrlDecode while forming/resolving that part.