Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having a problem when I try to use the response.redirect(url) and the url has the # character ... the webserver is taking out the # character plu any character that is after the #

Any idea how i can handle it
Posted

I wasn't able to duplicate the problem using response.redirect(urlstring):

VB
Dim gotourl As Uri = New Uri("http://www.red.com#hashthatstays")
Response.Redirect(gotourl.ToString)


...arrives at the page http://www.red.com#hashthatstays

However, if the file you're linking to has a hash in the filename:

http://www.google.com/bob#ofcars.htm, then you'll need to convert the hash character into the URL entity %23. This is because the server will be searching for the file or folder "bob", and the browser will attempt to go to the bookmark "ofcars.htm" once "bob" is opened.

http://www.google.com/bob%23ofcars.htm would open the correct file in this example (if google had a file named bob#ofcars.htm in the root folder. It doesn't, I checked ;o)

There's a full list of URL entities here: http://www.w3schools.com/tags/ref_urlencode.asp[^]

This gets tricky when you have a filename that contains a hash and a url with a bookmark:

The URL http://www.google.com/bob#ofcars.htm#fords needs to be transformed into

http://www.google.com/bob%23ofcars.htm#fords

to load properly in the browser - e.g. open the document and scroll to the bookmark "fords". Escaping the second hash causes it to become part of the filename the server attempts to find, and that'll result in a broken link.

Regular expressions and replacements can help parse a filename with hashes while preserving URL bookmarks.
 
Share this answer
 
You need to encode/decode url.

String url = "http://www.red.com#hashthatstays";
string encodedURL= HttpUtility.UrlEncode(url);
Response.Redirect(encodedURL);
 
Share this answer
 
try with UrlEncode

Response.Redirect(HttpUtility.UrlEncode(url));
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900