Trailing Point in MVC 5 WebRequest URL Calls 404

I am running MVC 5 and have a search API that creates the following link: /SearchedItem.?format=json where is SearchedItem. - user input in the search. This obviously causes the famous 404 due to the dot character. I reviewed all of the following solutions:

Dot character '.' in MVC Web API 2 for request, e.g. api / people / STAFF.45287

Dots in URL result in 404 using ASP.NET mvc and IIS

ApiController returns 404 when the identifier contains a period

However, not a single slash has been added (both /SearchedItem./?format=json and /SearchedItem.?format=json/ ), not RAMMFAR .

Look for new offers.

+5
source share
2 answers

You need to change your web.config, the endpoint allows iis to think that you are accessing an image.

Add the following to system.webServer / handlers (web.config)

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

Another suggestion is to set RunAllManagedModulesForAllRequests to true, but I would not recommend this. All static assets will be processed through .net code, and then :)

I see in your question that you checked the linked links. But are you sure? Because I walked past this in the past and above, this is my decision ...

+1
source

The most suitable way is encoding when you direct the url and decode in the corresponding action, which you can use HttpUtility to do the encoding and decoding

If you do not want to encode and decode, try adding a relaxedUrlToFileSystemMapping config, as described here

0
source

Source: https://habr.com/ru/post/1234202/


All Articles