ASP.NET Web API application gives 404 when deployed at IIS 7(ASP.NET Web API 应用程序在 IIS 7 上部署时提供 404)
问题描述
我有一个 ASP.NET Web API,在使用 localhost:1783 在IIS Express"上运行时可以正常工作
I have an ASP.NET Web API which works fine when running on "IIS Express" with localhost:1783
但是当我取消使用 IIS Express"然后按创建虚拟目录"时...
But when I uncross the "Use IIS Express" and then press "Create Virtual Directory"...
...我只收到 404 错误:
...I just get 404 errors:
任何想法有什么问题吗?谢谢!
Any ideas whats wrong? Thanks!
推荐答案
虽然标记的答案可以正常工作,但您真正需要添加到 webconfig 的是:
While the marked answer gets it working, all you really need to add to the webconfig is:
<handlers>
<!-- 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=""/>
</handlers>
请注意,这些都没有特定的顺序,尽管您希望在添加之前先删除.
Note that none of those have a particular order, though you want your removes before your adds.
我们最终得到 404 的原因是因为 URL 路由模块只在 IIS 中为网站的根目录启动.通过将模块添加到此应用程序的配置中,我们使模块在此应用程序的路径(您的子目录路径)下运行,并且路由模块启动.
The reason that we end up getting a 404 is because the Url Routing Module only kicks in for the root of the website in IIS. By adding the module to this application's config, we're having the module to run under this application's path (your subdirectory path), and the routing module kicks in.
这篇关于ASP.NET Web API 应用程序在 IIS 7 上部署时提供 404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:ASP.NET Web API 应用程序在 IIS 7 上部署时提供 404


- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 输入按键事件处理程序 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01