1

I have the below asp.net page which accepts a "url" query string key whose value can be an un-encoded url:

http://localhost:4104/WebSiteForTest/TinyUrl.aspx?url=http://www.google.co.uk/#hl=en&q=life&oq=life&aq=f&aqi=g-s1g9&aql=&gs_sm=3&gs_upl=2803373l2803701l2l2803826l4l4l0l0l0l0l188l453l0.3l3l0&bav=on.2,or.r_gc.r_pw.r_cp.,cf.osb&fp=94681dc4659502d1&biw=1680&bih=883

Now from this page, how would that be possible to read the text after ".aspx?"?

I checked the Request.Url.AbsoluteUri property and it only showed

"http://localhost:4104/WebSiteForTest/TinyUrl.aspx?url=http://www.google.co.uk/"

I also checked with the Request.QueryString with the below code:

 private void getQueryString()
    {
        var sb = new StringBuilder();

        var queryStringCount = Request.QueryString.Keys.Count;

        for (int keyIndex = 0; keyIndex < queryStringCount; keyIndex++)
        {
            sb.Append(Request.QueryString.Keys[keyIndex]).Append("=").Append(Request.QueryString[keyIndex]);
            if (keyIndex != (queryStringCount - 1))
            {
                sb.Append("&");
            }
        }
    }

However, the code after "#" doesn't appear in any query string.

how would that be possible to read the text after ".aspx?"?

if you say it's not possible, how Google uses "#" in their url then when you search for something?!

http://www.google.co.uk/#hl=en&site=&q=life&oq=life&aq=f&aqi=g-s1g9&aql=&gs_sm=3&gs_upl=3317l3630l0l3755l4l4l0l0l0l0l125l391l3.1l4l0&bav=on.2,or.r_gc.r_pw.r_cp.,cf.osb&fp=94681dc4659502d1&biw=1680&bih=849

Thanks,

The Light
  • 26,341
  • 62
  • 176
  • 258
  • can a querystring parameter contain unencoded data? – Jodrell Feb 16 '12 at 13:54
  • @Jodrell, it can e.g. http://www.google.co.uk/#hl=en&site=&q=life&oq=life&aq=f&aqi=g-s1g9&aql=&gs_sm=3&gs_upl=3317l3630l0l3755l4l4l0l0l0l0l125l391l3.1l4l0&bav=on.2,or.r_gc.r_pw.r_cp.,cf.osb&fp=94681dc4659502d1&biw=1680&bih=849 – The Light Feb 16 '12 at 14:07
  • @M.Babcock, please read the question again. – The Light Feb 16 '12 at 14:08
  • I still don't see any unencoded data in the query string but I think the answer you are looking for is in the Javascript of the google search page. – Jodrell Feb 16 '12 at 16:47

4 Answers4

4

It's not possible to get value after anchor on server side, you can check this with fiddler or something similar, you should deal with this on client. Browser simply strips all after anchor.

Retrieving Anchor Link In URL for ASP.Net

c# get complete URL with "#"

Update:

I don't know how google exactly do this, but if you look with fiddler after initial request there goes another without #, here is a fidller log for request from your question :

enter image description here

so my advice is look with fiddler how google do this, or maybe ask another question

Community
  • 1
  • 1
Antonio Bakula
  • 20,445
  • 6
  • 75
  • 102
0

Use Request.QueryString

http://localhost:4104/WebSiteForTest/TinyUrl.aspx?url=http://www.google.co.uk/#hl=en&q=life&oq=life&aq=f&aqi=g-s1g9&aql=&gs_sm=3&gs_upl=2803373l2803701l2l2803826l4l4l0l0l0l0l188l453l0.3l3l0&bav=on.2,or.r_gc.r_pw.r_cp.,cf.osb&fp=94681dc4659502d1&biw=1680&bih=883

<%=Request.QueryString("url")%> will get the ?url parameter

Sandeep Bansal
  • 6,280
  • 17
  • 84
  • 126
0

I assume you're using C# to do this. You can easily get the parameters and their values by iterating through the request object. Or in this case, since you know the name of the parameter, simply do this:

String url = Request.QueryString["url"];

More information on iterating through your request parameters can be found here.

0

The Uri Type works as well.

String yourHttpUri ="....";
Uri yourURI = new Uri(yourHttpUri);
yourURI.query // "?url=http://www.google.co.uk/"
yourURI.fragment // "#hl=en&q=life&oq=life&aq=f&aqi=g-s1g9&aql=&gs_sm=3&gs_upl=2803373l2803701l2l2803826l4l4l0l0l0l0l188l453l0.3l3l0&bav=on.2,or.r_gc.r_pw.r_cp.,cf.osb&fp=94681dc4659502d1&biw=1680&bih=883"

Edit:

Have you tried Request.Url.ToString(); (And create a new Uri from the result)

Alex
  • 7,901
  • 1
  • 41
  • 56
  • please read the question again. I'd like to get the url and query string from within that page e.g. on page_load. – The Light Feb 16 '12 at 14:09