0

I have a OWIN WebAPI project which works in the OwinSelfHost, but always results in 404 when hosted on IIS 10, the only thing that works is the initial page public/index.html. I'm running IIS 10 on a Windows 10 machine. I'm using Dapper, Npgsql and Postgresql database.

I have tried a few tricks that I read through googling, so far, no luck, Here is my Web.config:

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.6" />
        <httpRuntime targetFramework="4.6" />
        <httpModules>
            <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
        </httpModules>
    </system.web>

    <system.webServer>
        <!-- runAllManagedModulesForAllRequests: Make sure that we have OWIN handle static files, too. -->
        <modules runAllManagedModulesForAllRequests="true">
            <remove name="ApplicationInsightsWebTracking" />
            <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
        </modules>

        <staticContent>
            <!--clear /-->
        </staticContent>


        <handlers>
            <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
            <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
        </handlers>
        <validation validateIntegratedModeConfiguration="false" />
        <directoryBrowse enabled="true" />
        <defaultDocument>
            <files>
                <add value="public/index.html" />
            </files>
        </defaultDocument>
    </system.webServer>

    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

And packages.config:

<?xml version="1.0" encoding="utf-8"?>
<packages>
    <package id="Dapper" version="1.50.1" targetFramework="net46" />
    <package id="Dapper.Contrib" version="1.50.0" targetFramework="net46" />
    <package id="Dapper-Async" version="1.03" targetFramework="net46" />
    <package id="Microsoft.ApplicationInsights" version="2.0.0" targetFramework="net46" />
    <package id="Microsoft.ApplicationInsights.Agent.Intercept" version="1.2.1" targetFramework="net46" />
    <package id="Microsoft.ApplicationInsights.DependencyCollector" version="2.0.0" targetFramework="net46" />
    <package id="Microsoft.ApplicationInsights.JavaScript" version="0.22.9-build00167" targetFramework="net46" />
    <package id="Microsoft.ApplicationInsights.PerfCounterCollector" version="2.0.0" targetFramework="net46" />
    <package id="Microsoft.ApplicationInsights.Web" version="2.0.0" targetFramework="net46" />
    <package id="Microsoft.ApplicationInsights.WindowsServer" version="2.0.0" targetFramework="net46" />
    <package id="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" version="2.0.0" targetFramework="net46" />
    <package id="Microsoft.AspNet.Cors" version="5.2.3" targetFramework="net46" />
    <package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net46" />
    <package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net46" />
    <package id="Microsoft.AspNet.WebApi.Cors" version="5.2.3" targetFramework="net46" />
    <package id="Microsoft.AspNet.WebApi.Owin" version="5.2.3" targetFramework="net46" />
    <package id="Microsoft.AspNet.WebApi.OwinSelfHost" version="5.2.3" targetFramework="net46" />
    <package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net46" />
    <package id="Microsoft.Azure.AppService.ApiApps.Service" version="0.9.16" targetFramework="net46" />
    <package id="Microsoft.Owin" version="3.0.1" targetFramework="net46" />
    <package id="Microsoft.Owin.FileSystems" version="3.0.1" targetFramework="net46" />
    <package id="Microsoft.Owin.Host.HttpListener" version="3.0.1" targetFramework="net46" />
    <package id="Microsoft.Owin.Hosting" version="3.0.1" targetFramework="net46" />
    <package id="Microsoft.Owin.StaticFiles" version="3.0.1" targetFramework="net46" />
    <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net46" />
    <package id="Newtonsoft.Json" version="9.0.1" targetFramework="net46" />
    <package id="Npgsql" version="3.1.6" targetFramework="net46" />
    <package id="Owin" version="1.0" targetFramework="net46" />
    <package id="OwinHost" version="3.0.1" targetFramework="net46" />
    <package id="Swashbuckle" version="5.0.0" targetFramework="net46" />
    <package id="Swashbuckle.Core" version="5.0.0" targetFramework="net46" />
    <package id="System.IdentityModel.Tokens.Jwt" version="4.0.0" targetFramework="net46" />
    <package id="WebActivatorEx" version="2.0.6" targetFramework="net46" />
</packages>
user1510580
  • 137
  • 1
  • 1
  • 7
  • did you register asp.net? If not, try `aspnet_regiis -i` using the visual studio command line tools as an administrator – Khanh TO Jul 30 '16 at 13:21
  • @Khan I just tried that, removed the site and added the site again, didn't help. – user1510580 Jul 30 '16 at 15:32
  • It's not about removing the site, it's about registering your asp.net with IIS – Khanh TO Jul 31 '16 at 15:17
  • @Khan the site needs no registration, that's why it didn't make a difference. I defined the site within IIS Manager (port 8002) and localhost:8002 does pull up public/index.html. – user1510580 Jul 31 '16 at 20:55
  • without registration, the site is still able to server index.html because it's a static file, but to run your asp.net code (c#), you need to register asp.net with IIS – Khanh TO Aug 01 '16 at 12:59
  • @Khan, I didn't read the message of that command carefully, I thought it ran successfully, but actually the output says that the command is not supported on the OS. Do you suggest any alternative to that? Thanks. – user1510580 Aug 02 '16 at 01:05
  • Microsoft (R) ASP.NET RegIIS version 4.0.30319.0 Administration utility to install and uninstall ASP.NET on the local machine. Copyright (C) Microsoft Corporation. All rights reserved. Start installing ASP.NET (4.0.30319.0). This option is not supported on this version of the operating system. Administrators should instead install/uninstall ASP.NET 4.5 with IIS8 using the "Turn Windows Features On/Off" dialog, the Server Manager management tool, or the dism.exe command line tool. For details see http://go.microsoft.com/fwlink/?LinkID=216771. Finished instal ASP.NET (4.0.30319.0). – user1510580 Aug 02 '16 at 01:07
  • still does not work? – Khanh TO Aug 02 '16 at 13:03
  • @Khanh, nope, I tried some more things, including downloading and installing .NET Framework 4.6.2. – user1510580 Aug 04 '16 at 02:21
  • I see that you use owin to host your project (there are owin packages). If so, you have to add these under ``: `` – Khanh TO Aug 04 '16 at 13:09
  • @Khanh thanks a lot. That worked! – user1510580 Aug 05 '16 at 12:07
  • After a great research of other causes, this worked for me, I was very frustrated, but I still have a question. I have 2 IIS 7.5, one needed this config and the other didn't, can you help me out to understand this? @KhanhTO – Luciano Santos Oct 03 '17 at 22:22
  • @Luciano Santos: It's hard to tell why. Is there a chance that you have this in your machine.config or in your parent site so it gets inherited in your app? – Khanh TO Oct 06 '17 at 13:19
  • I watched the machine.config and the applicationHost.config and none had the config nor the other machine was explicitily removing it =/ Thanks though – Luciano Santos Oct 16 '17 at 19:11

1 Answers1

2

You have to add OwinHttpHandler to your pipeline:

<handlers>
       <add name="Owin" verb="*" path="*" type="Microsoft.Owin.Host.SystemWeb.OwinHttpHandler, Microsoft.Owin.Host.SystemWeb" />
 </handlers>
Khanh TO
  • 48,509
  • 13
  • 99
  • 115