Get full URL with hash to use as ReturnUrl
Asked Answered
C

1

10

I have such URL

localhost/Login/LogOn?ReturnUrl=/#&q=my%20search%20word&f=1//447044365|2//4

I need to get hash parameters to navigate in the application after authentication.

I try to catch it like this

<input name="returnUrl" value="<%= ViewContext.HttpContext.Request.Url.PathAndQuery %>" type="hidden" />

But result is

/Login/LogOn?ReturnUrl=/

I tried to take away "/#" in the URL, then I get whole URL. But I need to use this URL as it is.

Why was URL cutted?

Cause answered 4/4, 2011 at 9:14 Comment(0)
P
23

The browser does not send the hash fragment to the server. It used on the client-side only. If you need it you will have to access it through client-side script.

Plosive answered 4/4, 2011 at 9:28 Comment(2)
Thanks! I have just added $("#returnUrl").val(location.hash); to place it in the input.Cause
With client-side URL processing like this, be mindful of inject/hijack attacks. Make sure the consumer of this value is untrusting and validates it.Interfluent

© 2022 - 2024 — McMap. All rights reserved.