tags:

views:

109

answers:

5

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.

+6  A: 

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

Noon Silk
Let me get this straight (so I can skip the question next time it appears): someone clicks on a link containing a # (meaning an anchor, a position, on a webpage). The browser sends a GET request to the server containing only the address of the entire page, with no anchor, fragment or whatever. When the server returns the page, the browser knows where to position it so the location of the anchor is visible. The other answers mention Javascript because it's client-side and should have access to the anchor.
pavium
yes, that's correct
levinalex
A: 

Are you sure you receive GET requests like this? You probably only receive http://localhost/controller/List.

A: 

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.

Mehmet Duran
+1  A: 

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.

Eamon Nerbonne
A: 

'#' 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.

Lion_cl