Minimum API Routing Setup API - Shared Hosting Help

I have a simple SUPER web API. It is not openly secure and just provides free data. I would like to move it from my personal server to shared hosting (ex: GoDaddy), but I'm having problems.

There are many similar questions around 404 status when trying to access the routing attribute APIs in shared hosting solutions. But none of them worked for me. This is my SUPER simple current setup:


  • Create a new .Net Framework 4.5 EMPTY C # Web Application named YourApplicationName
  • Make sure all checkboxes and packages are NOT checked.
  • Add new object "Global.asax"
  • Replace all C # content with the following:

    using System.Web.Http;
    namespace YourApplicationName
    {
        public class Global : System.Web.HttpApplication
        {
            protected void Application_Start()
            {
                System.Web.Mvc.AreaRegistration.RegisterAllAreas();
                GlobalConfiguration.Configure((HttpConfiguration config) => { config.MapHttpAttributeRoutes(); });
            }
        }
    
        public class TestController : System.Web.Http.ApiController
        {
            [System.Web.Http.Route("api/Test")]
            public string Get()
            {
                return "Test Info";
            }
        }
    }
    
          

  • Replace the Web.config file with the following:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <system.web>
        <customErrors mode="Off" />
        <compilation debug="true" targetFramework="4.5" />
        <httpRuntime targetFramework="4.5" />
      </system.web>
      <system.webServer>
        <handlers>
          <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
          <remove name="OPTIONSVerbHandler" />
          <remove name="TRACEVerbHandler" />
          <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
        </handlers>
      </system.webServer>
    </configuration>
    
          

  • Remove ALL Links other than System and System.Web

  • PM> Install the following two packages:

Microsoft.AspNet.Mvc installation package

Installation Package Microsoft.AspNet.WebApi.WebHost


With this I can work in Dev, publish on my personal IIS, run on my company IIS Servers, or even publish on azure ( http://suamereapi.azurewebsites.net/api/Test ) and if I go to the route I, accordingly, I will return "Test Information".

But when I publish my shared hosting I get a 404 status. Note that the mvc controllers that return Views

work fine on shared hosting and not on ApiControllers

.

Potential Issue 1 is that the IIS pipeline is not configured as integrated on the hosted account. Of course, I checked that I had it set to Integrated.

Possible issue 2: Moreso related to API NOT using attribute routing is that Route Register Routes should arrive before GlobalConfiguration. This does not apply in configuring the auto-config routing-attribute API.

Potential Problem 3: Some of the DLLs are not in the shared hosting of the GAC, nor are they published from the local setup as they are not copied locally . I changed Copy-Local to a few settings from none to whatever is required for all links.

Possible issue 4: Sharing hosts with configuration paths due to virtual directories for subdomains or not. This is fixed by adding rewrite

to Web.config as such:

rewrite>
<rules>
<rule name="Remove Virtual Directory">
<match url=".*" />
<action type="Rewrite" url="{R:0}" />
</rule>
</rules>
</rewrite>

      

Potential Issue 5: Some people say that to fix the issue, you need to add runAllManagedModulesForAllRequests="true"

and work with httpHandlers to remove and manually add extension handlers and UrlRoutingModules.

I have done all combinations of these workarounds, but I cannot imagine what the real problem is. Please let me know what I might be missing, I spent a few days here.

+3


source to share





All Articles