5

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.

Community
  • 1
  • 1
eYe
  • 1,695
  • 2
  • 29
  • 54

2 Answers2

1

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

NicoJuicy
  • 3,435
  • 4
  • 40
  • 66
  • I believe MVC 5 is the problem – eYe Oct 27 '15 at 01:12
  • MVC 5 is a framework on top of Asp.Net... Do you have something more? – NicoJuicy Oct 27 '15 at 07:49
  • Solutions listed in my questions fail under MVC 5, people confirm that within answer comments. – eYe Oct 27 '15 at 13:16
  • Did you change your project from MVC 4 to MVC 5 and used the walkthrough given at : http://www.asp.net/mvc/overview/releases/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2? – NicoJuicy Oct 27 '15 at 14:56
  • No, the project has originally been written using MVC 5 – eYe Oct 27 '15 at 15:02
0

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

Community
  • 1
  • 1
zash707
  • 245
  • 2
  • 11