简体   繁体   English

对带有参数的webapi get方法的请求返回404

[英]Request to webapi get method with parameters returns 404

I get a 404 error when calling this method on my WebApi. 在WebApi上调用此方法时出现404错误。

On my ApiController I have a ArchiveTradingConfiguration method. 在我的ApiController上,我有一个ArchiveTradingConfiguration方法。

public class TradingConfigurationController : ApiController
{
[AcceptVerbs("GET")]
    public bool ArchiveTradingConfiguration(string correlationId, string symbol)
    {
...
    }
}

Here is my startup.cs 这是我的startup.cs

public static class Startup
{
 public static void ConfigureApp(IAppBuilder appBuilder)
    {
    var config = new HttpConfiguration();
        config.EnableCors();

        config.Routes.MapHttpRoute(
        name: "ApiWithAction",
        routeTemplate: "api/{controller}/{action}/",
        defaults: null
        );

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

        config.Routes.MapHttpRoute(
        name: "ArchiveTradingConfiguration",
        routeTemplate: "api/{controller}/{correlationId}/{symbol}"
        );
     }
}

When I make the request i use: 当我发出请求时,我使用:

var correlationId  = "SomeGuidAsString";
var symbol = "SomeStringValue"
var url = "api/TradingConfiguration/ArchiveTradingConfiguration/" + correlationId + "/" + symbol;

eg http://localhost:8421/api/TradingConfiguration/ArchiveTradingConfiguration/034f7d92-dd02-46b3-9db2-11990ea5860c/SomeStringValue 例如http:// localhost:8421 / api / TradingConfiguration / ArchiveTradingConfiguration / 034f7d92-dd02-46b3-9db2-11990ea5860c / SomeStringValue

Any idea? 任何想法?

It is working now. 现在正在工作。 I made 2 changes. 我进行了2次更改。 I dont know if the first was needed. 我不知道是否需要第一个。 The second was for sure. 第二是肯定的。

My Action contained the name of my controller. 我的动作包含我的控制器的名称。 Changed the name of the action to Archive 将动作名称更改为“存档”

I my route config I had forgot to add /{action}/ 我的路线配置我忘记添加/ {action} /

routeTemplate: "api/{controller}/{action}/{correlationId}/{symbol}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM