简体   繁体   English

IIS 经典模式 .NET Web API 调用返回 4

[英]IIS Classic Mode .NET Web API Call returns 404 Error

I have a pre-existing VB.NET web application running on IIS 8 in Windows Server 2012 R2.我有一个预先存在的 VB.NET web 应用程序在 ZAEA23489CE3AA2B6406EB2023 中的 IIS 8 上运行。 The application needs to handle a new API call (ex. localhost/test/ping) which I implemented using the APIController interface.应用程序需要处理我使用 APIController 接口实现的新 API 调用(例如 localhost/test/ping)。 I was able to successfully run the API call on my local Visual Studio, but once I deploy it to IIS, the url returns a 404 error.我能够在本地 Visual Studio 上成功运行 API 调用,但是一旦将其部署到 IIS,url 就会返回 404 错误。

After some digging and research, part of the problem I believe is the web app does not have ExtensionlessUrlHandler-Integerated-4.0 in the handler mapping.经过一些挖掘和研究,我认为部分问题是 web 应用程序在处理程序映射中没有 ExtensionlessUrlHandler-Integerated-4.0。 Looking into the configurations, apparently part of the pre-condition is the application cannot be me in classic mode, which mine is.查看配置,显然部分先决条件是应用程序不能是经典模式下的我,我的是。 I cannot switch to integrated mode which will break my app.我无法切换到会破坏我的应用程序的集成模式。

Is there a way around this limitation.有没有办法绕过这个限制。


Update: Adding the web.config更新:添加 web.config

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true" />
  <handlers>
    <add name="MVC" path="*." verb="*" type="" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="File" requireAccess="None" allowPathInfo="false" preCondition="classicMode,runtimeVersionv2.0,bitness32" responseBufferLimit="4194304" />
  </handlers>
</system.webServer>

Update: Added Source Code更新:添加源代码

TestController.vb测试控制器.vb

<RoutePrefix("message")>
Public Class PingController
    Inherits ApiController

  Public Sub New() {
     ...
  }

      <Route("")>
    <HttpGet>
    Public Function GetMessage As String
        Return "Hello World"
    End Function
 ...

Global.asax全球.asax

<script runat="server">
    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)

        GlobalConfiguration.Configure(AddressOf WebApiConfig.Register)
    End Sub
...

WebApiConfig.vb WebApiConfig.vb

Public Class WebApiConfig
    Public Shared Sub Register(ByVal Configuration As HttpConfiguration)
        Configuration.MapHttpAttributeRoutes()
    End Sub
End Class

If you have full access over your server, you could create the so-called Wildcard Script Map so that you can use the default ASP.NET MVC route table with IIS 7.0 (in classic mode) or IIS 6.0. If you have full access over your server, you could create the so-called Wildcard Script Map so that you can use the default ASP.NET MVC route table with IIS 7.0 (in classic mode) or IIS 6.0. This Wildcard Script Map will map all requests to the webserver to the ASP.NET framework.此通配符脚本 Map 会将 map 对网络服务器的所有请求发送到 ASP.NET 框架。

enable a wildcard script map for IIS 7.0 (classic mode):为 IIS 7.0(经典模式)启用通配符脚本 map:

1)Open IIS, Select your site/application 1)打开 IIS,Select 您的站点/应用程序

2)Double-click the Handler Mappings from the middle pane 2) 双击中间窗格中的处理程序映射

在此处输入图像描述

3)Click the Add Wildcard Script Map link 3)点击添加通配符脚本Map链接

在此处输入图像描述

4)Enter the path to the aspnet_isapi.dll file (You can copy this path from the PageHandlerFactory script map) 4)输入aspnet_isapi.dll文件的路径(可以从PageHandlerFactory脚本映射复制这个路径)

Enter the name MVC Click the OK button输入名称 MVC 点击确定按钮

在此处输入图像描述

Add runAllManagedModulesForAllRequests="true" for web.config/system.webServer/handlers section为 web.config/system.webServer/handlers 部分添加 runAllManagedModulesForAllRequests="true"

Refer below link for more detail:有关更多详细信息,请参阅以下链接:

Using ASP.NET MVC with Different Versions of IIS (C#) 使用 ASP.NET MVC 与不同版本的 IIS (C#)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM