简体   繁体   中英

Request to webapi get method with parameters returns 404

I get a 404 error when calling this method on my WebApi.

On my ApiController I have a ArchiveTradingConfiguration method.

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

Here is my 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

Any idea?

It is working now. I made 2 changes. 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}/

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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