Solved

asp.net c# read query string from referering page

Posted on 2010-09-21
7
672 Views
Last Modified: 2013-11-07
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
Comment
Question by:zattz
  • 3
  • 3
7 Comments
 
LVL 10

Expert Comment

by:james-ct16
Comment Utility
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
 
LVL 2

Expert Comment

by:Ahrensy
Comment Utility
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
 
LVL 10

Expert Comment

by:james-ct16
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:zattz
Comment Utility
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
 
LVL 10

Accepted Solution

by:
james-ct16 earned 500 total points
Comment Utility
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
 

Author Comment

by:zattz
Comment Utility
           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
 

Author Comment

by:zattz
Comment Utility
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
.Net Web Site Password specs 2 19
C# Application Local DB Connection String 23 57
Long URL in SMS 6 22
Create XML 5 30
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now