[ASP.NET MVC] URL Routing URL contains "/" slash

ASP.NET MVC URL contains "/" slash


I encountered a situation is, URL parameters that may have brought the "/" slash (user input) like the following

1. normal operation

http: // localhost: 45405 / Home / Product name = HTC / M8 / mobile phone sets?

2. operating normally

http: // localhost: 45405 / Home / Product name = 'anti-up' white toothpaste _ King?

So far we have not, but we have to look good and make URL optimization SEO, we'll do like the following URL Rewriting

   1: // Products
   2:            routes.MapRoute(
   3:               name: "Product",
   4: url: "Product / {name}",
   5:               defaults: new { controller = "Home", action = "Product", name = UrlParameter.Optional });


1. Error

http: // localhost: 45405 / commodity / HTC / M8 / mobile phone sets

unnamed

2. operating normally

http: // localhost: 45405 / goods / 'anti-up' white toothpaste _ King

This time we will be able to add a * in front of the route name.

   1: // Products
   2:             routes.MapRoute(
   3:                name: "Product",
   4: url: "Product / {* name}",
   5:                defaults: new { controller = "Home", action = "Product", name = UrlParameter.Optional });



If the error also please do not skimp on advanced predecessors advise, thank you.

 

Original: Large column  [ASP.NET MVC] URL Routing URL contains "/" slash


Guess you like

Origin www.cnblogs.com/chinatrump/p/11516519.html