ASP.NET Web API 应用程序在 IIS 7 上部署时提供 404 [英] ASP.NET Web API application gives 404 when deployed at IIS 7

查看:36
本文介绍了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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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