tags:

views:

66

answers:

2

Hi all, When i do this:

Response.Redirect("./blah.aspx?key=my value with spaces");

It sends the browser to:

mysite/blah.aspx?key=my%20value%20with%20spaces

Now i understand why it's doing this - for the sake of ancient browsers that would choke on the spaces. But really, what i want is to have a nice-looking url with spaces instead of %'s everywhere, because it works just the same.

Is there some way to stop response.redirect urlencoding my spaces?

Thanks a lot

+2  A: 

you could always replace spaces in your key with scores before redirecting, and "decoding" them into spaces again after the fact like so:

string urlString = "./blah.aspx?key=my value with spaces";
Response.Redirect(urlString.Replace(' ','-'));

and on the page that grabs the querystring:

string queryKey = Request["key"].Replace('-',' ');

(be careful of nulls in Request["key"] here though)

Nico
+4  A: 

You can't have a valid URL with spaces, the space character is actually illegal in an URL.

You can't make the Response.Redirect method avoid encoding the spaces, it's not designed to create an illegal URL.

Guffa
+1. Spot on. The encoding is there for a REASON, why do people try and fight against it?
RPM1984
I know, you're right, but this is an intranet app, i'm fine with breaking the rules a bit. Any ideas how to do it?
Chris
I don't think it's possible to do that, is it that important to have spaces in your URLs? why not just replace them with something else instead, spaces would look horrible in URLs anyways..
Nico
exactly. just use underscores or hyphen.
RPM1984
You could make you own Redirect method that breaks any rules you want. All it does really is to replace the current output with a redirection page, and call Response.End.
Guffa