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
基础教程推荐
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
