5

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
Chen
  • 103
  • 1
  • 9
  • Do you have a virtual directory on IIS? If so, make sure your relative URL for API controller is correct. In this case, it can work in local IISExpress but fail on IIS. I've got into similar issues sometimes in the past. Anyway, I think this is some sort of a routing issue, but it's hard to say more without source codes. – AndrewSilver Jul 16 '20 at 16:51
  • @AndrewSilver I don't think I am using a virtual directory. I added the source code in the original description too. – Chen Jul 17 '20 at 23:26
  • I think I might have figured out part of the problem. I added some logging statements around my code and I noticed global.asax startApplication is not getting called. I see the App_global.asax.compiled & App_global.dll, but there in a bin directory. – Chen Jul 23 '20 at 18:30

1 Answers1

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.

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#)

Jalpa Panchal
  • 8,251
  • 1
  • 11
  • 26
  • I followed your instructions but I still see the same issue as before. I updated my answer above to include the changes I made to the web.config. – Chen Jul 08 '20 at 17:34
  • I did some more digging, and I think this solution only applies for MVC, not ApiController. – Chen Jul 13 '20 at 14:57
  • @Chen try to check the url is right or not and make sure you installed the right asp.net framework version. – Jalpa Panchal Jul 22 '20 at 02:29
  • So I believe my url is correct. It works locally on VS unless IIS changes that somehow. As for the correct ASP.NET version, I have 4.5 ASP.NET & Extension installed. – Chen Jul 22 '20 at 18:58
  • @Chen you could to reinstall the iis. – Jalpa Panchal Jul 29 '20 at 09:16