1

I have created a web API that works when I run it locally (Visual Studio start issexpress).

I use the following url for testing: http://localhost:51178/api/atf/new?id=MyID2&type=onetime&build=Adara-Daily&sequence=pvr

However, when we try to deploy it on a server running IIS 8.5 we always get a 404 Not Found error.

Here is a sample of my controller:

[RoutePrefix("api/atf")]
public class AtfController : ApiController
{
    [Route("new")]
    [HttpGet]
    public HttpResponseMessage StartNewAtf(string id, string type, string build, string sequence, string recipients, string ip, string port)
    {
        AtfRequestRecord arr = new AtfRequestRecord(id, type, build, sequence, recipients);
        arr.IP = ip;
        arr.Port = port;

        AtfManager am = new AtfManager();
        return am.CreateAtfHostBuildInstance(arr, Request);
    }

    [Route("new")]
    [HttpGet]
    public HttpResponseMessage StartNewAtf(string id, string type, string build, string sequence, string ip, string port)
    {
        string recipients = "NoRecipients";

        AtfRequestRecord arr = new AtfRequestRecord(id, type, build, sequence, recipients);
        arr.IP = ip;
        arr.Port = port;

        AtfManager am = new AtfManager();
        return am.CreateAtfHostBuildInstance(arr, Request);
    }

    [Route("new")]
    [HttpGet]
    public HttpResponseMessage StartNewAtf(string id, string type, string build, string sequence, string recipients)
    {
        AtfRequestRecord arr = new AtfRequestRecord(id, type, build, sequence, recipients);

        AtfManager am = new AtfManager();
        return am.CreateAtfInstance(arr, Request);
    }

    [Route("new")]
    [HttpGet]
    public HttpResponseMessage StartNewAtf(string id, string type, string build, string sequence)
    {
        string recipients = "NoRecipients";

        AtfRequestRecord arr = new AtfRequestRecord(id, type, build, sequence, recipients);

        AtfManager am = new AtfManager();
        return am.CreateAtfInstance(arr, Request);
    }

In my WebApiConfig.cs file I have the following routes mapped:

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        config.Routes.MapHttpRoute(
            name: "NewAtfApi",
            routeTemplate: "api/atf/new",
            defaults: new { Controller = "atf", Action = "StartNewAtf" }
        );

        config.Routes.MapHttpRoute(
            name: "GetStatusApi",
            routeTemplate: "api/atf/status",
            defaults: new { Controller = "atf", Action = "GetStatus" }
        );

        config.Routes.MapHttpRoute(
            name: "AbortSequenceApi",
            routeTemplate: "api/atf/abortsequence",
            defaults: new { Controller = "atf", Action = "AbortSequence" }
        );

        config.Routes.MapHttpRoute(
            name: "SequenceDoneApi",
            routeTemplate: "api/atf/sequencedone",
            defaults: new { Controller = "atf", Action = "SequenceDone" }
        );

        //config.Routes.MapHttpRoute(
        //    name: "DefaultApi",
        //    routeTemplate: "api/{controller}/{id}",
        //    defaults: new { id = RouteParameter.Optional }
        //);

        // Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type.
        // To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries.
        // For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712.
        //config.EnableQuerySupport();

        // To disable tracing in your application, please comment out or remove the following line of code
        // For more information, refer to: http://www.asp.net/web-api
        config.EnableSystemDiagnosticsTracing();
    }
}

In my Web.config file I have added the following based on answers I've found on this site:

 <system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules>
  <remove name="UrlRoutingModule" />
  <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule" preCondition="integratedMode,runtimeVersionv4.0" />
</modules>
<handlers>
  <remove name="UrlRoutingHandler" />
  <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" />
  <add name="UrlRoutingHandler" path="*" verb="*" type="System.Web.HttpForbiddenHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>

I've also tried adding

<module runAllManagedModulesForAllRequests="true"/>

to my Web.config file, but it didn't help.

This is my first attempt at any web development and was hoping someone could point me in the right direction to fix my issue.

WGrant
  • 11
  • 2

0 Answers0