尝试访问 Web 时出现 404 错误 API 2 部署到 IIS 7.5 的服务

404 Error when trying to access Web API 2 Service deployed to IIS 7.5

我使用 Web API 2 框架创建了一个独立的 REST 服务。该项目不包含 UI,因为该服务将在另一个域的其他地方使用。

在使用浏览器内 REST 客户端进行测试时,当 运行 在本地和所有 HTTP 方法 work/return 时,服务完全正常。

但是,在发布服务并部署到 IIS 7.5 之后,我无法在 REST 客户端中访问我的服务的任何路由的任何资源。我不断收到 404 - Resource Not Found 错误。

我已经做过的事情:

在我的 Web.Config 中添加了以下内容:

<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
        <handlers>
            <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
            <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
        </handlers>
  </system.webServer>

确保 AppPool 是正确的(据我所知这是正确的):

了解我的发布配置文件的发布配置可能也很有用:

IIS 绑定:

我尝试在 REST 客户端中访问我的服务的示例URL如下:

如有任何其他尝试,我们将不胜感激。

原来我的绑定有点不正确!由于我将其托管在子域上,因此我的绑定中不需要 www.。删除这 4 个字符后工作正常!