Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

QueryString C# Code

How do I change the code below so that my querystring can be captured from anywhere in the URL (it will always be preceded with an & (ampersand).

It might be something like:
http://someurl/somefile.aspx?source=somepage.aspx&oneqs=4&anotherqs=Susan%20Smith
string[] split = Request.Url.ToString().Split(new char[] {'/'}, System.StringSplitOptions.None);
string endsWith = split[split.Length - 1].ToLower();
endsWith = (endsWith.Split(new char[] {'?'}, System.StringSplitOptions.None))[0];
switch (endsWith)
{
    case "Susan Smith": BranchApp = "Susan Smith"; break;
}

Open in new window

0
net_susan
Asked:
net_susan
  • 2
3 Solutions
 
Jens FiedererTest Developer/ValidatorCommented:
Why not just use the normal QueryString property (HttpRequest..::.QueryString ) which already gives you a Name Value collection parsed for your enjoyment?
0
 
net_susanAuthor Commented:
Would you please post an example?
0
 
TechTiger007Commented:
in your code try
Request.QueryString["source"]
Request.QueryString["oneqs"]
Request.QueryString["anotherqs"]
to get the values


0
 
Jens FiedererTest Developer/ValidatorCommented:
Let's say our HttpRequest is "Request".

Somewhere you have foo=bar  (say "http://x.com/main.asp?foo=bar" or "http://x.com/main.asp?baz=bletch&foo=bar&qux=guy")

Then Request.QueryString["foo"]  should just give you "bar".

0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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