I have a Labels controller and its action

 public ActionResult ShowLabel(string label) 

it should display tags. I want to prescribe a route for this action, I register it like this

 routes.MapRoute( name: "ShowLabel", url: "Label/{label}", defaults: new { controller = "Labels", action = "ShowLabel" } ); 

Everything works with labels like C# , kkk and others without a dot. But with the label ASP.NET does not work and gives an error 404. So I understand it does not work due to the fact that there is a dot in the tag name, if it doesn’t work for other tags with a dot, it also does not work. It is not clear why it does not work, and how to make it work so that it would work with a dot. Performance in general with such labels does not enter.

Here is an example URL

  1. http://localhost:58791/Label/тег3 - works
  2. http://localhost:58791/Label/С# - works
  3. http://localhost:58791/Label/ASP.NET - does not work

And if the default routes everything works with any labels. http://localhost:58791/Labels/ShowLabel?label=ASP.NET - works if you don’t make a ShowLabel route.

I tried to write restrictions:

 routes.MapRoute( name: "ShowLabel", url: "Label/{label}", defaults: new { controller = "Labels", action = "ShowLabel" }, constraints: new { label = @"[.#\-+_$@\w]+" } ); 

the same result.

Checked, also for + does not work in the name, but for - works.

I tried to add the same settings

 <system.webServer> <security> <requestFiltering allowDoubleEscaping="true" /> </security> </system.webServer> 

+ earned as well never works.

  • @Grundy thanks, now it works. - Dmitry Polyanin
  • If you found the solution yourself, you should add it as an answer - Grundy
  • @Grundy It's not me, it was you who helped)) - Dmitry Polyanin
  • Not :-) I was too lazy to translate and check which of the answers could help - Grundy

1 answer 1

That is what helped fix the situation.

Prescribe

 <add name="ApiURIs-ISAPI-Integrated-4.0" path="/Label/*" verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> 

in system.webServer / handlers in web.config

Taken from an English-language response - https://stackoverflow.com/questions/11728846/dots-in-url-causes-404-with-asp-net-mvc-and-iis

True, such an entry only works for the Label controller, which for me is a limitation, and if necessary for different controllers and routes, you will have to register several times. But in my project, this is only for labels (label) and necessary, so this record is enough.

  • try path="*" - Grundy
  • I thought about it, I think that with this, static files like my.css and my.js will also be processed by such a handler. and so they are supposed to be processed by IIS - Dmitry Polyanin