skip to Main Content

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


  1. Chosen as BEST ANSWER

    @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


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

    <system.webServer>
    
        <rewrite>
            <rules>
                <clear />
                <rule name="AddTrailingSlashRule1" stopProcessing="true">
                    <match url="(.*[^/])$" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    </conditions>
                    <action type="Redirect" url="{R:1}/" />
                </rule>
            </rules>
        </rewrite>
    
    </system.webServer>
    

    EDIT 2023-03-17: Unfortunately I had to abandon this approach because when I used this, my Angular app would produce the following error:

    Failed to load module script: Expected a Javascript module script but the server responded with a MIME type of "text/html".  Strict MIME type checking is enforced for module scripts per HTML spec.
    

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search