marc.d
marc.d

Reputation: 3844

How do i get the url part after a "#" from HttpRequestBase

i am receiving GET requests like this

http://localhost/controller/List#SearchGuid=755d259d-e7c9-4c5a-bf2a-69f65f63df8d

and i need to read the SearchGuid which is after the #. unfortunately the HttpRequestBase seems the hide everything past a #.

does somebody know how i could still read the SearchGuid from within the controller action?

tia.

Upvotes: 9

Views: 7060

Answers (4)

Victor Gelmutdinov
Victor Gelmutdinov

Reputation: 489

'#' Fragment is accessible client-side only, however IE8 submitting URL include #fragment part.

You can use Ajax to make it works. Something like:

var fragment = location.hash; // on page load
$.get('/yoururl' + '?' + fragment.replace(/^.*#/, ''));

It will looks like you are requesting URL#fragment on client-side, but actually, it will request URL?fragment and you can work with it on server-side.

One thing you should remember about - server page will be requested twice, so second one (Ajax request - check the request header "X-Requested-With=XMLHttpRequest") you should take.

P.S. Google applications using same solution, as I'm seeing from Firebug.

Upvotes: 2

Eamon Nerbonne
Eamon Nerbonne

Reputation: 48066

If you want to process url "fragments" (that's what those things after the '#' are called), you'll need to do so client side. Fragments are not transmitted to the server.

Either redesign the protocol to use a query string (replace '#' by '?'), or use javascript on the client to do the necessary processing - which may include making a server request that encodes the fragment in a URI query string.

Upvotes: 3

Mehmet Duran
Mehmet Duran

Reputation: 176

You can get that part in JavaScript on the client side using window.location.hash, set it to some hidden input onsubmit so they'll also get sent to the server.

Upvotes: 2

Noon Silk
Noon Silk

Reputation: 55092

You can't, it doesn't get sent to the server.

Upvotes: 20

Related Questions