我有一个ASP.NET Web API,当在localhost:1783上通过"IIS Express"运行时可以正常工作。
但是当我取消勾选"Use IIS Express"并按下"创建虚拟目录"之后...
...我只会得到404错误:
有什么想法是错的吗?谢谢!
我有一个ASP.NET Web API,当在localhost:1783上通过"IIS Express"运行时可以正常工作。
但是当我取消勾选"Use IIS Express"并按下"创建虚拟目录"之后...
...我只会得到404错误:
有什么想法是错的吗?谢谢!
<modules>
<!-- Your other remove tags-->
<remove name="UrlRoutingModule-4.0"/>
<!-- Your other add tags-->
<add name="UrlRoutingModule-4.0" path="*" verb="*" type="System.Web.Routing.UrlRoutingModule" preCondition=""/>
</modules>
system.web.urlroutingmodule未实现iHttpHandlerFactory...
。相反,按照这里的建议,我在<configuration><system.webserver><modules>下添加了配置,并删除了路径和动词属性,但仍然出错。 - Rafael Emshoff
- Alex对我来说,除了拥有runAllManagedModulesForAllRequests="true"
之外,我还必须编辑下面的"path"
属性。 以前我的路径属性是"*."
,这意味着它只在包含点字符的url上执行。 然而,我的应用程序的url没有包含点。 当我将路径切换到"*"
时,它就可以工作了。
这是我现在拥有的:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule"/>
</modules>
<handlers>
<remove name="WebDAV" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*" verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
2. 确保以下内容在Web API部署的服务器的bin文件夹中可用:
•System.Net.Http
•System.Net.Http.Formatting
•System.Web.Http.WebHost
•System.Web.Http
如果使用Visual Studio进行发布,则这些程序集不会默认复制到bin文件夹中,因为Web API包是通过Nuget在开发机器上安装的。但是,如果您希望将这些文件作为Visual Studio发布的一部分,请将这些程序集的CopyLocal设置为True。
http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html
http://bartwullems.blogspot.com/2012/06/optimize-performance-of-your-web.html
string baseUrl = NavigationManager.BaseUri.ToString();
NavigationManager.NavigateTo(**baseUrl** + $"api/Download/DownloadFile?FileName="
+ sFilename, true);
对我而言,这个问题与其他答案略有不同,因为我只在OPTIONS上收到404错误,尽管我已经在我的集成Extensionless URL Handler选项中明确指定了OPTIONS。非常令人困惑。
为了解决这个问题,需要在web.config中添加以下安全节点 - 完整的system.webserver包含上下文:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule" />
</modules>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<remove name="WebDAV" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
<security>
<requestFiltering>
<verbs>
<remove verb="OPTIONS" />
</verbs>
</requestFiltering>
</security>
</system.webServer>
虽然这不是完美的答案,但它是在谷歌上搜索“ IIS OPTIONS 404” 的第一个结果,所以我希望这能帮助到某些人;今天我花了一个小时。
我曾经遇到同样的问题。经过大量的研究和开发,我找到了问题所在。
但只要您的配置正确,也就是aspnet 64位和IIS都正常,那么我看到的唯一问题就是“web api采用本地目录路径”,因此您需要避免它。像这样:~../../../api/products/
非常感谢您发布这个问题。我学到了很多关于iis和配置文件中的其他设置。