尝试在IIS 8.5上访问Web API时找不到404

时间:2015-12-08 16:50:19

标签: c# iis http-status-code-404 asp.net-web-api

我创建了一个在本地运行时可以运行的Web API(Visual Studio start issexpress)。

我使用以下网址进行测试:http://localhost:51178/api/atf/new?id=MyID2&type=onetime&build=Adara-Daily&sequence=pvr

但是,当我们尝试在运行IIS 8.5的服务器上部署它时,我们总是会收到404 Not Found错误。

以下是我的控制器示例:

[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);
    }

在我的WebApiConfig.cs文件中,我映射了以下路由:

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();
    }
}

在我的Web.config文件中,我根据我在本网站上找到的答案添加了以下内容:

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

我也尝试过添加

<module runAllManagedModulesForAllRequests="true"/>

到我的Web.config文件,但它没有帮助。

这是我对任何网络开发的第一次尝试,并希望有人能指出我正确的方向来解决我的问题。

0 个答案:

没有答案