Solved

query string issue with pound sign

Posted on 2014-07-24
3
427 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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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 …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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

13 Experts available now in Live!

Get 1:1 Help Now