2

I've got a route defined in the WebApiConfig:

 config.Routes.MapHttpRoute(name: "dav", routeTemplate:
 "api/values/{*file}", defaults: new { controller = "Values", action =
 "Get" });

The {*file} part of the route template defines that the number of parameters are variable. This is documentented on MSDN.

Got a controller with action Get:

[AcceptVerbs("GET")]
[ActionName("Get")]
public HttpResponseMessage Get(param string[] file)
{}

When run the uri http://[mymachine]/api/values/1/1/2/3/ hits the method Get. Only the file array is empty.

Also tried the usual like:

public HttpResponseMessage Get(string[] file)

And

public HttpResponseMessage Get(string file)

Both end in a 404.

Any ideas?

2
  • 2
    Have you tried applying the FromUri attribute to the file parameter for any of those combinations? Commented Jan 24, 2014 at 10:04
  • 1
    It was a wild stab in the dark, and I didn't know which (if any) of your specs would actually work. You ought to post the working solution as an answer (rather than putting it at the bottom of the question) and mark it as accepted (you have to wait a bit to do this, IIRC). That way people know that you've solved the problem and don't need more help with it. Commented Jan 24, 2014 at 11:21

1 Answer 1

2

Adding attribute FromUri solves the problem.

Thanks to @Damien_The_Unbeliever.

[AcceptVerbs("GET")] [ActionName("Get")] 
public HttpResponseMessage Get([FromUri] string file)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.