IIS 10.0, VS 2022, .NET Framework 4.7.2 Web API
I inherited a web api application that I am told worked 100% the last time it was published (at least a year ago, maybe 2). However, now I get 404 not found when the attribute contains a period (both in IDE using IIS and when published to IIS on server).
I tried creating a new web api app with 2 methods:
[HttpPost]
[Route("BatchData/ProcessResponseByString/{requestId}")]
public HttpResponseMessage ProcessResponseByString(string requestId)
{
return new HttpResponseMessage()
{
Content = new StringContent($"String:{requestId}")
};
}
[HttpPost]
[Route("BatchData/ProcessResponseByDouble/{requestId:double}")]
public HttpResponseMessage ProcessResponse(double requestId)
{
return new HttpResponseMessage()
{
Content = new StringContent($"Double:{requestId}")
};
}
These urls work:
https://localhost:44352/BatchData/ProcessResponseByString/12345
https://localhost:44352/BatchData/ProcessResponseByDouble/12345
These urls fail with 404 not found:
https://localhost:44352/BatchData/ProcessResponseByString/12345.67
https://localhost:44352/BatchData/ProcessResponseByDouble/12345.67
Perhaps an IIS upgrade changed the way routing is resolved in IIS?
Any ideas on how to resolve this?
Thanks.
2
Answers
@Paritosh posted the link (Why is my Web API method with double args not getting called?) and suggested the / workaround (thanks for the link), but the answer that worked for me was after the / suggestion - updating webconfig
For ASP.NET/IIS, Suprotim Agarwal provides web.config rewrite code here: https://www.devcurry.com/2015/07/allowing-dots-in-aspnet-mvc-paths.html – this rewrite interactively adds a slash to the end of the URL (that contains a period) when it is not a request for a directory or file:
EDIT 2023-03-17: Unfortunately I had to abandon this approach because when I used this, my Angular app would produce the following error:
It was hard to be sure this rewrite was causing the error because when I removed it from web.config the error persisted, even if I recycled my IIS App Pool. Something persists on a per-browser basis – if I started up a different browser the state of web.config (no-longer having the rewrite) would mean that app worked again.