Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trailing dot in MVC 5 WebRequest URL causes 404

I am running MVC 5 and have a search API that produces the following link: /SearchedItem.?format=json where SearchedItem. is the user's input into search. This obviously causes a famous 404 due to a dot character. I've looked into all of the following solutions:

Dot character '.' in MVC Web API 2 for request such as api/people/STAFF.45287

Dots in URL causes 404 with ASP.NET mvc and IIS

ApiController returns 404 when ID contains period

However, neither adding a slash (tried both /SearchedItem./?format=json and /SearchedItem.?format=json/) nor RAMMFAR worked.

Looking for any new suggestions.

like image 582
eYe Avatar asked Nov 09 '22 03:11

eYe


1 Answers

You have to change your web.config, the trailing dot let's iis think you are accessing an image.

Add the following within the 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 suggest would be to set RunAllManagedModulesForAllRequests to true, but i wouldn't recommend that. All static assets would be handled through the .net code then :)

I see in your question that you checked related links. But are you sure? Because i have came accross this in the past and above was my solution...

like image 94
NicoJuicy Avatar answered Nov 15 '22 06:11

NicoJuicy