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
基础教程推荐
- C# 9 新特性——record的相关总结 2023-04-03
- 从 C# 控制相机设备 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 将数据集转换为列表 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 如果条件可以为空 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
