locked
ASP.NET Core Web API deployed in IIS returning only HTTP Code 404 RRS feed

  • Question

  • User2109203056 posted

    I have a new Web API developed in ASP.NET Core. This Web API is supposed to be deployed in IIS and will have to work over SSL, so I have the [HttpsRequired] attribute on all my controllers. I struggle to make it work while deployed, so, for now, I relaxed the requirements and commented out those attributes. Doing so, I was able to create two bindings in IIS, one for HTTPS and one for HTTP. Given that my Web API is created in ASP.NET Core, I followed the deployment steps Rick Strahl has in his excellent blog post. I have selected "No Managed Code" for the .NET CLR version. The IIS machine is a 64-bit Windows Server 2012 R2 environment - not sure whether this matters or not. The .NET Core Windows Server Hosting bundle has been installed on the server and I can see the AspNetCoreModule listed in the Modules grid.

    If I try to access the Web API (I created a very simple GET method that returns some information regarding the assembly) with Fiddler, I get a 404 error. For now, I run Fiddler on the same machine, so I tried all combinations (localhost, IP address and full machine name in the domain).

    If I run the Web API as a stand-alone application, I have it listening to "http://localhost:5000" and I can see it is working when I access it with Fiddler.

    No errors are logged in the EventViewer. Does anyone have any suggestion on how to troubleshoot this issue?

    TIA, Eddie

    Tuesday, October 18, 2016 8:06 PM

All replies

  • User-460007017 posted

    Hi EddieL,

    Have you configured routing for your web api?

    This link provide the information about routing for asp.net core web api:

    https://docs.asp.net/projects/api/en/latest/autoapi/Microsoft/AspNetCore/Mvc/HttpGetAttribute/index.html#Microsoft.AspNetCore.Mvc.HttpGetAttribute

    Besides, You could try to add following configuration in web config:

    system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
    
    </system.webServer>

    I recommend you enable the failed request tracing and post the error log here. The failed request tracing log provide the detail of IIS module and process.

    https://www.iis.net/learn/troubleshoot/using-failed-request-tracing/troubleshooting-failed-requests-using-tracing-in-iis

    Best Regards,

    Yuk Ding

    Wednesday, October 19, 2016 9:27 AM
  • User2109203056 posted

    Hi Yuk,

    I will try to enable tracing and will post the error trace here. I think that routing is fine because I disabled Windows Authentication and only left Anonymous Authentication and in that situation, the Web API replies. I think it has something to do with how the Windows Authentication for ASP.NET Core Web APIs is handled by IIS. I found a lot of similar questions on GitHub: this and this. I have a lot of reading to do. But maybe if you see the traced error, you can quickly pinpoint me to what the actual issue is.

    Thanks,

    Eddie

    Wednesday, October 19, 2016 6:08 PM
  • User1278090636 posted

    Hi EddieL,

    When using IIS with asp.net core web application, the IIS works as reverse proxy.

    Please check if you set the correct setting of aspNetCore section in your web.config.

    <aspNetCore processPath="dotnet"
                    arguments=".\YourApplication.dll" 
                    stdoutLogEnabled="false" 
                    stdoutLogFile=".\logs\stdout" 
                    forwardWindowsAuthToken="false" />

    And you can check if the AspNetCoreModule is on top of the StaticModule in the ordered module list.

    IIS Modules Overview : The Official Microsoft IIS Site

    Best Regards,

    Jean

    Monday, October 24, 2016 8:16 AM