Asp.net mvc 4 404 WebApi调用出错

Asp.net mvc 4 404 WebApi调用出错,asp.net-mvc-4,angular,asp.net-web-api,web-config,Asp.net Mvc 4,Angular,Asp.net Web Api,Web Config,我面临着一个棘手的情况,我有一个angular2应用程序,可以很好地部署到服务器上,但是当对WebApi服务器进行请求调用时,我得到了404个错误的响应。WebApi调用在本地环境中工作正常,但在实时服务器上失败 <!--Redirect selected traffic to index --> <rule name="Index Rule" stopProcessing="true"> <match url=".*" />

我面临着一个棘手的情况,我有一个angular2应用程序,可以很好地部署到服务器上,但是当对WebApi服务器进行请求调用时,我得到了404个错误的响应。WebApi调用在本地环境中工作正常,但在实时服务器上失败

<!--Redirect selected traffic to index -->
    <rule name="Index Rule" stopProcessing="true">
      <match url=".*" />
      <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_URI}" matchType="Pattern" pattern="/api/" negate="true" />
      </conditions>
      <action type="Rewrite" url="/index.html" />
    </rule>
webapp托管在网络中的子域下。登录屏幕上显示的所有angular2文件都已正确加载,但无法与WebApi控制器进行通信。任何帮助都将不胜感激

更新: 下面是WebApiConfig.cs文件

        public static void Register(HttpConfiguration config)
    {
        // Web API configuration and services

        // Web API routes
        config.MapHttpAttributeRoutes();

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

WebApi有一些规则将控制器方法(名称、参数)与传入请求相匹配。 我猜这里WebApi可能需要一个参数来通过ID获取记录。您正在使用GET,它隐式地需要一个“ID”来获取记录

出于测试目的,请尝试

1) 在方法中使用参数。 公共IHttpActionResult GetTaskItemsAnon(int id=1)

2) 删除方法的[httpget]指令
注意不要与控制器类中的其他方法发生冲突

能否发布Postman的快照以及如何进行API调用?另外,您可以尝试从您的操作方法中删除[AllowAnonymous]属性并重试吗?我已经删除了[AllowAnonymous],但没有任何更改。对于Postman,我只是简单地使用一个普通的GET请求,而不使用任何参数来访问相应的URL。我知道这在Postman中是正确的,因为在localhost环境下,Postman成功地在控制器中实现了WebApi操作。您可以在RouteConfig.cs中发布代码吗?我没有RouteConfig.cs,我有一个WebApicConfig.cs文件,因为我使用WebApi作为服务器。请参阅WebApiConfig.csc的更新。是否可以在WebApiConfig.cs中将-routeTemplate:“api/{controller}/{id}”更改为-routeTemplate:“api/{controller}/{action}/{id}”,然后重试?
        public static void Register(HttpConfiguration config)
    {
        // Web API configuration and services

        // Web API routes
        config.MapHttpAttributeRoutes();

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