Solved

query string issue with pound sign

Posted on 2014-07-24
3
417 Views
Last Modified: 2014-07-25
Im having an issue with users entering pound signs into values that are going into query string and messing up the url.

customer
textbox value:  #beta

query string
Then when they press a button to redirect to a new page they get a 404 error.

404
Here is the code.

  Response.Redirect(Rainbow.HttpUrlBuilder.BuildUrlByPath("Rating/Edit Contract/Change Contract","&spot=y" + "&cust=" + txtCustomer.Text + "&div=" + txtDivision.Text)); 

Open in new window

The offending code there is the &cust variable.  If a user enters a # in front of the value it causes a 404 error.

On the page im redirecting to im using the variable as such.

  if (Request.QueryString["cust"] != null)
                {
                    txtCustomer.Text = Request.QueryString["cust"];
                }

Open in new window


So im wondering if there is a way for me to handle special chars like * or # in the query string.

Thanks
0
Comment
Question by:hougie40
  • 2
3 Comments
 
LVL 25

Expert Comment

by:Shaun Kline
Comment Utility
You should use the HttpServerUtility.UrlEncode to encode your values for inclusion in your URL.
See reference: http://msdn.microsoft.com/en-us/library/zttxte6w(v=vs.110).aspx.
0
 

Author Comment

by:hougie40
Comment Utility
The url.encode works fine with those urls that have # in them but not with those that have * in them.

I should have mentioned earlier that customer code can be preceded with # or *.  So in the case of the * i am not sure how to handle those.
0
 
LVL 25

Accepted Solution

by:
Shaun Kline earned 500 total points
Comment Utility
The asterisk is a special reserved character and is not encoded with that utility. You will need to encode and decode it manually using a string replace method. The correct encoding value is %2A.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

772 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

10 Experts available now in Live!

Get 1:1 Help Now