在IIS 10 OWIN的WebAPI项目提供的所有操作404 [英] OWIN WebApi project on IIS 10 gives 404 on all operations

查看:338
本文介绍了在IIS 10 OWIN的WebAPI项目提供的所有操作404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个OWIN的WebAPI项目,该项目在OwinSelfHost的作品,但在IIS托管10时,结果总是在404,唯一可行的就是初始页面公共/ index.html的。我是Windows 10的机器上运行IIS 10。我使用的是短小精悍,Npgsql和PostgreSQL数据库。



我都试过,我通过谷歌搜索阅读一些技巧,到目前为止,没有运气,这是我的Web.config :

 < XML版本=1.0编码=UTF-8>? 
< - !
关于如何配置ASP.NET应用程序的更多信息,请访问:
http://go.microsoft.com/fwlink/?LinkId=169433
- >
<结构>
<&的System.Web GT;
<编译调试=真targetFramework =4.6/>
<的httpRuntime targetFramework =4.6/>
<&的HttpModules GT;
<添加名称=ApplicationInsightsWebTrackingTYPE =Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule,Microsoft.AI.Web/>
< /&的HttpModules GT;
< /system.web>

< system.webServer>
< - runAllManagedModulesForAllRequests:确保我们OWIN处理静态文件,太。 - >
<模块runAllManagedModulesForAllRequests =真正的>
<清除NAME =ApplicationInsightsWebTracking/>
<添加名称=ApplicationInsightsWebTrackingTYPE =Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule,Microsoft.AI.Web前提=managedHandler/>
< /模块>

< staticContent>
<! - 清/ - >
< / staticContent>


<&处理GT;
<清除NAME =ExtensionlessUrlHandler - 集成 - 4.0/>
<添加名称=ExtensionlessUrlHandler - 集成 - 4.0PATH =*。动词=*TYPE =System.Web.Handlers.TransferRequestHandler前提=integratedMode,runtimeVersionv4.0/>
< /处理器>
<验证validateIntegratedModeConfiguration =FALSE/>
<启用directoryBrowse =真/>
< defaultDocument>
<&文件GT;
<增加价值=公共/ index.html的/>
< /文件>
< / defaultDocument>
< /system.webServer>

<&运行GT;
< assemblyBinding的xmlns =瓮:架构 - 微软COM:asm.v1>
< dependentAssembly>
< assemblyIdentity名称=Microsoft.Owin公钥=31bf3856ad364e35文化=中性/>
< bindingRedirect oldVersion =0.0.0.0-3.0.1.0NEWVERSION =3.0.1.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity名称=Newtonsoft.Json公钥=30ad4fe6b2a6aeed文化=中性/>
< bindingRedirect oldVersion =0.0.0.0-9.0.0.0NEWVERSION =9.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity名称=System.Net.Http.Formatting公钥=31bf3856ad364e35文化=中性/>
< bindingRedirect oldVersion =0.0.0.0-5.2.3.0NEWVERSION =5.2.3.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity名称=System.Web.Http公钥=31bf3856ad364e35文化=中性/>
< bindingRedirect oldVersion =0.0.0.0-5.2.3.0NEWVERSION =5.2.3.0/>
< / dependentAssembly>
< / assemblyBinding>
< /运行>
< /结构>

和packages.config:

 <?XML版本=1.0编码=UTF-8>?; 
<套餐及GT;
<包ID =小巧玲珑版本=1.50.1targetFramework =net46/>
<包ID =Dapper.Contrib版本=1.50.0targetFramework =net46/>
<包ID =小巧玲珑,异步版本=1.03targetFramework =net46/>
<包ID =Microsoft.ApplicationInsights版本=2.0.0targetFramework =net46/>
<包ID =Microsoft.ApplicationInsights.Agent.Intercept版本=1.2.1targetFramework =net46/>
<包ID =Microsoft.ApplicationInsights.DependencyCollector版本=2.0.0targetFramework =net46/>
<包ID =Microsoft.ApplicationInsights.JavaScript版本=0.22.9-build00167targetFramework =net46/>
<包ID =Microsoft.ApplicationInsights.PerfCounterCollector版本=2.0.0targetFramework =net46/>
<包ID =Microsoft.ApplicationInsights.Web版本=2.0.0targetFramework =net46/>
<包ID =Microsoft.ApplicationInsights.WindowsServer版本=2.0.0targetFramework =net46/>
<包ID =Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel版本=2.0.0targetFramework =net46/>
<包ID =Microsoft.AspNet.Cors版本=5.2.3targetFramework =net46/>
<包ID =Microsoft.AspNet.WebApi.Client版本=5.2.3targetFramework =net46/>
<包ID =Microsoft.AspNet.WebApi.Core版本=5.2.3targetFramework =net46/>
<包ID =Microsoft.AspNet.WebApi.Cors版本=5.2.3targetFramework =net46/>
<包ID =Microsoft.AspNet.WebApi.Owin版本=5.2.3targetFramework =net46/>
<包ID =Microsoft.AspNet.WebApi.OwinSelfHost版本=5.2.3targetFramework =net46/>
<包ID =Microsoft.AspNet.WebApi.WebHost版本=5.2.3targetFramework =net46/>
<包ID =Microsoft.Azure.AppService.ApiApps.Service版本=0.9.16targetFramework =net46/>
<包ID =Microsoft.Owin版本=3.0.1targetFramework =net46/>
<包ID =Microsoft.Owin.FileSystems版本=3.0.1targetFramework =net46/>
<包ID =Microsoft.Owin.Host.HttpListener版本=3.0.1targetFramework =net46/>
<包ID =Microsoft.Owin.Hosting版本=3.0.1targetFramework =net46/>
<包ID =Microsoft.Owin.StaticFiles版本=3.0.1targetFramework =net46/>
<包ID =Microsoft.Web.Infrastructure版本=1.0.0.0targetFramework =net46/>
<包ID =Newtonsoft.Json版本=9.0.1targetFramework =net46/>
<包ID =Npgsql版本=3.1.6targetFramework =net46/>
<包ID =Owin版本=1.0targetFramework =net46/>
<包ID =OwinHost版本=3.0.1targetFramework =net46/>
<包ID =Swashbuckle版本=5.0.0targetFramework =net46/>
<包ID =Swashbuckle.Core版本=5.0.0targetFramework =net46/>
<包ID =System.IdentityModel.Tokens.Jwt版本=4.0.0targetFramework =net46/>
<包ID =WebActivatorEx版本=2.0.6targetFramework =net46/>
< /包>


解决方案

您必须添加 OwinHttpHandler 来您的管道:

 <&处理GT; 
<添加名称=Owin动词=*路径=*TYPE =Microsoft.Owin.Host.SystemWeb.OwinHttpHandler,Microsoft.Owin.Host.SystemWeb/>
< /处理器>


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>

解决方案

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>

这篇关于在IIS 10 OWIN的WebAPI项目提供的所有操作404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆