Click here to Skip to main content
15,888,088 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have used ASP.net with C#.
I want to remove special character like %20 from url.
For URL Rewritting i have used Global.asax.
Please help me out with this.
sample url
localhost:24882/WebSite2/ProductList/396/Micromax%20Ninja%20A89
i want only
http://localhost:24882/WebSite2/ProductList/396/Micromax_Ninja_A89.


If you know any other method to URL Rewritting then let me know
Posted
Updated 17-Oct-13 20:31pm
v2

Hi,

You can use

C#
// FOR URL ENCODE
string destinationURL = "http://localhost:24882/WebSite2/ProductList/396/Micromax_Ninja_A89";
HttpContext.Current.Server.UrlEncode(destinationURL);

// FOR URL DECODE
string url = "localhost:24882/WebSite2/ProductList/396/Micromax%20Ninja%20A89";
HttpContext.Current.Server.UrlDecode(url);


Note : (In url %20 is used for single blank space not for underscore)

One more thing what you actually need, Because In URL rewriting I think(as I used) there is no need for URL Encoding/Decoding as you need...

And one more thing never put answer in your posted question, If you have any query then post comment..

THANKS
ASP.NET BLOG - hemant[^]
 
Share this answer
 
v4
Comments
Member 8666669 18-Oct-13 3:17am    
Thanks for ur ans and give me ur response about my wrong thing

I know that the %20 is for space.
By doing this can it remove this as i have used global.asax to url rewritting.
let me know url encode and decode is written in which page also.
Hemant Singh Rautela 18-Oct-13 3:24am    
I think you need URL REWRITING CODE :

// IN GLOBAL.ASAX
void Application_BeginRequest(object sender, EventArgs e)
{
string CurrentURL_Path = Request.Url.AbsoluteUri.ToLower();
string url = CurrentURL_Path.Substring(CurrentURL_Path.LastIndexOf('/')+1);
if (CurrentURL_Path.Contains("mycategory")) // your condition comes here as i used for sample
{
HttpContext MyContext = HttpContext.Current;
MyContext.RewritePath("~/product.aspx?catid=21", false);
}
}

In above example code
www.mywebsite.com/mycategory --->Rewrite to -->www.mywebsite.com/product.aspx/product.aspx?catid=21
Hemant Singh Rautela 18-Oct-13 4:02am    
Then whats the problem you can used it where you want to read url..
string url = "URLRewritting/ProductList/2/micromax%20ninja%20A285";
string newurl = HttpContext.Current.Server.UrlDecode(url);
Member 8666669 18-Oct-13 4:51am    
is this code is write in productDescription page
 
Share this answer
 
 
Share this answer
 
v2

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