Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

QueryString C# Code

Posted on 2008-10-28
4
Medium Priority
?
2,297 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 23

Assisted Solution

by:Jens Fiederer
Jens Fiederer earned 1400 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 600 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 1400 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

715 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