Solved

query string issue with pound sign

Posted on 2014-07-24
3
460 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
[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
3 Comments
 
LVL 26

Expert Comment

by:Shaun Kline
ID: 40217863
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
ID: 40218197
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 26

Accepted Solution

by:
Shaun Kline earned 500 total points
ID: 40219366
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

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

756 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