Solved

QueryString C# Code

Posted on 2008-10-28
4
2,290 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
Comment Utility
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
Comment Utility
Would you please post an example?
0
 
LVL 13

Assisted Solution

by:TechTiger007
TechTiger007 earned 150 total points
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

763 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

7 Experts available now in Live!

Get 1:1 Help Now