IIS Classic Mode .NET Web API Call returns 404 Error

Viewed 464

I have a pre-existing VB.NET web application running on IIS 8 in Windows Server 2012 R2. The application needs to handle a new API call (ex. localhost/test/ping) which I implemented using the APIController interface. 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.

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. 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

<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

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

  Public Sub New() {
     ...
  }

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

Global.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
1 Answers

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.

enable a wildcard script map for IIS 7.0 (classic mode):

1)Open IIS, Select your site/application

2)Double-click the Handler Mappings from the middle pane

enter image description here

3)Click the Add Wildcard Script Map link

enter image description here

4)Enter the path to the aspnet_isapi.dll file (You can copy this path from the PageHandlerFactory script map)

Enter the name MVC Click the OK button

enter image description here

Add runAllManagedModulesForAllRequests="true" for web.config/system.webServer/handlers section

Refer below link for more detail:

Using ASP.NET MVC with Different Versions of IIS (C#)

Related