【发布时间】:2020-10-27 23:12:48
【问题描述】:
我有一个预先存在的 VB.NET Web 应用程序在 Windows Server 2012 R2 的 IIS 8 上运行。应用程序需要处理我使用 APIController 接口实现的新 API 调用(例如 localhost/test/ping)。我能够在本地 Visual Studio 上成功运行 API 调用,但是一旦将其部署到 IIS,url 就会返回 404 错误。
经过一些挖掘和研究,我认为部分问题是网络应用程序在处理程序映射中没有 ExtensionlessUrlHandler-Integerated-4.0。查看配置,显然部分先决条件是应用程序不能是经典模式下的我,我的是。我无法切换到集成模式,这会破坏我的应用程序。
有没有办法绕过这个限制。
更新:添加 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>
更新:添加源代码
TestController.vb
<RoutePrefix("message")>
Public Class PingController
Inherits ApiController
Public Sub New() {
...
}
<Route("")>
<HttpGet>
Public Function GetMessage As String
Return "Hello World"
End Function
...
全球.asax
<script runat="server">
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
GlobalConfiguration.Configure(AddressOf WebApiConfig.Register)
End Sub
...
WebApiConfig.vb
Public Class WebApiConfig
Public Shared Sub Register(ByVal Configuration As HttpConfiguration)
Configuration.MapHttpAttributeRoutes()
End Sub
End Class
【问题讨论】:
-
您在 IIS 上有虚拟目录吗?如果是这样,请确保您的 API 控制器的相对 URL 正确。在这种情况下,它可以在本地 IISExpress 中工作,但在 IIS 上失败。我过去有时会遇到类似的问题。无论如何,我认为这是某种路由问题,但是没有源代码很难说更多。
-
@AndrewSilver 我认为我没有使用虚拟目录。我也在原始描述中添加了源代码。
-
我想我可能已经解决了部分问题。我在我的代码周围添加了一些日志语句,我注意到 global.asax startApplication 没有被调用。我看到 App_global.asax.compiled & App_global.dll,但在 bin 目录中。
标签: asp.net vb.net iis iis-8 windows-server-2012-r2