Solved

QueryString C# Code

Posted on 2008-10-28
4
2,294 Views
Last Modified: 2012-05-05
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
Comment
Question by:net_susan
  • 2
4 Comments
 
LVL 23

Assisted Solution

by:Jens Fiederer
Jens Fiederer earned 350 total points
ID: 22824770
Why not just use the normal QueryString property (HttpRequest..::.QueryString ) which already gives you a Name Value collection parsed for your enjoyment?
0
 
LVL 1

Author Comment

by:net_susan
ID: 22824793
Would you please post an example?
0
 
LVL 13

Assisted Solution

by:TechTiger007
TechTiger007 earned 150 total points
ID: 22824851
in your code try
Request.QueryString["source"]
Request.QueryString["oneqs"]
Request.QueryString["anotherqs"]
to get the values


0
 
LVL 23

Accepted Solution

by:
Jens Fiederer earned 350 total points
ID: 22824899
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Install Problem 13 34
SqlDataBase 7 54
vs2013 publish -- can I have publish create a directory and copy files into it during install? 3 25
Please explain purpose of GZIP 4 37
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

821 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