Solved

query string issue with pound sign

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

770 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