eYe
eYe

Reputation: 1733

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.

Upvotes: 5

Views: 785

Answers (2)

zash707
zash707

Reputation: 275

Most suitable way is to encode once you route to url and decode in the respective action you can use HttpUtility to perform encoding and decoding

If you don't want to encode and decode then try adding relaxedUrlToFileSystemMapping config as explained Here

Upvotes: 0

NicoJuicy
NicoJuicy

Reputation: 3528

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...

Upvotes: 1

Related Questions