Solved

QueryString C# Code

Posted on 2008-10-28
4
2,293 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Angular JS Route 3 68
What .NET URL re-routing tool did I use? 2 53
Device Location 4 29
Following an example - Why do I need to click Save button twice? 3 25
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

816 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