[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 743
  • Last Modified:

asp.net c# read query string from referering page

Hi

I know you can access parts of the query string in asp.net using Request.QueryString["session"]

Does anybody know how to access the various parts of the query string of the refering page?
0
zattz
Asked:
zattz
  • 3
  • 3
1 Solution
 
james-ct16Commented:
Howdy

To the best of my knowledge that is simply not possible. To achieve this you would have to re transmit from the previous page ie place them in hidden form values or append them to the link address

Regards

James
0
 
AhrensyCommented:
Request.QueryString returns the variables passed to the webpage via the GET method.

Example:
http://www.example.com/index.asp?variable1=45&variable2=34


--index.asp--
<%
Response.Write("<br>" + Request.QueryString("variable1"));
Response.Write("<br>" + Request.QueryString("variable2"));
%>

Open in new window

0
 
james-ct16Commented:
however having just said that you could get some of that detail out of Request.ServerVariables("HTTP_REFERER") if it is set by the browser however it is not always so you cant account for it
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
zattzAuthor Commented:
I'm looking for a way to parse the referer so I can access it in a nice way like the request's parameters... ie: Referer.QueryString["session"]
0
 
james-ct16Commented:
So just to extend my last post further, if the browser does include the refering page then you would have to pick the key pairs out yourself through string manipulation. Code example attached it will need more error checking.

I must stress this is not a reliable method though.

What you should be doing is submitting these values as part of a form or as part of your link.


string refer = Request.ServerVariables("HTTP_REFERER");
            if (!string.IsNullOrEmpty(refer) && refer.Contains("?"))
            {
                refer = refer.Substring(refer.IndexOf("?")+1);
                string[] keyValuePairs = refer.Split('&');
                Dictionary<string, string> queryString = new Dictionary<string, string>();
                foreach (string s in keyValuePairs)
                {
                    string[] pair = s.Split('=');
                    if (pair.Length == 2)
                    {
                        queryString.Add(pair[0], pair[1]);
                    }
                }

                System.Diagnostics.Debug.WriteLine(queryString["variable1"]);
            }

Open in new window

0
 
zattzAuthor Commented:
           string r = Request.ServerVariables("HTTP_REFERER");
            r = r.Substring(r.IndexOf("?") + 1);
            HttpRequest h = new HttpRequest("", "http://www.site.com", r);
            MessageBox.Show(h.QueryString["XYZ"]);
0
 
zattzAuthor Commented:
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now