this is my first post on stackoverlow and I couldn't find a solution to this in any other posts, so here it goes:
I have a web page that is sending two query strings in the url:
example.aspx?name=<%=name%>&sku=<%=sku%>
I then collect the values using Request.QueryString["name"];
and Request.QueryString["sku"];
When I view the url on the source of the page sending the query strings everything looks fine, but if "name" contains a forward slash (/) it will somehow get tacked on to the end of "sku" when I retrieve the value of the query string. I've tried to replace the / with %2F but that doesn't work. If the "name" query string doesn't have a slash everything looks correct.
Any Ideas?
Edit: I ended up having to double encode (server.urlencode) and double decode for it to work correctly. Thanks for all your help!
Use URL encoding to format the values appropriately, assuming the forward slash in the name is intentional and would like to be extracted with the end result.
Note that there are at least two ways to go about this easily, for example using the static class
HttpUtility
or, when in the context of aPage
, using theServer
property:You could just trim the end value of the sku request:
Actually, your should encode your values for URLs with HttpServerUtility.UrlEncode method:
EDIT:
let's check this with the values you provided:
name = Bellagio™ 16 1/2" High Downbridge Outdoor Wall Light
,sku = 46910
: firstly I created a page with 2 properties:and then add link definition to the page:
and then grab these values (click the link firstly):
these values are exactly the same as you provided:
Bellagio™ 16 1/2\" High Downbridge Outdoor Wall Light
and46910
.Unfortunatelly, I was unable to reproduce an incorrect URL you post in your first comment:
LifeSizePDF.aspx?productname=Bellagio&%238482%3b+16+1%2f2&quot%3b+High+Downbridge+Outdoor+Wall+Light&shortsku=46910%2f