tags:

views:

37

answers:

2

I am passing a return Url to a controller, but i am not using an mvc helper ie actionlink. before I redirect from the controller with this url should I use Server.UrlEncode? seems not to work properly.

A: 

Server.UrlEncode encodes the url to a string with appropriate codes for characters in the url. See http://msdn.microsoft.com/en-us/library/ms525738%28VS.90%29.aspx

Kangkan
+2  A: 

UrlEncode will replace illegal url characters with their escape codes. Then entire url should not be escaped.

Here's a sample usage:

string MyURL = "http://www.contoso.com/articles.aspx?title=" + Server.UrlEncode("ASP.NET Examples");

Response.Write("<a href=" + MyURL + "> ASP.NET Examples </a>");

This would output http://www.contoso.com/articles.aspx?title=ASP.NET+Examples

Ryan