3

Following routes are in my WebApiConfig.cs:

// routing for /profile/
config.Routes.MapHttpRoute(
    name: "profile",
    routeTemplate: "users/{userid}/profil",
    defaults: new { controller = "User", userid = RouteParameter.Optional }
);

// routing for /messages/
config.Routes.MapHttpRoute(
    name: "messages",
    routeTemplate: "users/{userid}/messages",
    defaults: new { controller = "User", userid = RouteParameter.Optional }
);

And this is the according code in the Controller:

public class UserController {

    [HttpGet]
    [ActionName("profile")]
    public HttpResponseMessage GetProfile(int userid) {}


    [HttpGet]
    [ActionName("messages")]
    public HttpResponseMessage GetMessages(int userid) {}

}

So basically I want to have two methods in the same controller which both take the same parameters, but are mapped to different URLs. Right now I keep getting an error about multiple actions being found - even though I have a distinction of the ActionName attribute.

What am I doing wrong? Can I have two GET methods in the same controller, taking the same input but being called on different URLs?

Thanks!

2
  • 1
    You are aware of the typo in your routes for profil ? your actionname is profile Commented Oct 1, 2012 at 10:33
  • Ah, thank you. This wasn't the real code though, so that couldn't have been the issue. Commented Oct 1, 2012 at 10:56

1 Answer 1

1

Have you tried to specifically add action name on the routing definition ?

i.e.

 config.Routes.MapHttpRoute(
name: "profile",
routeTemplate: "users/{userid}/profil",
defaults: new { controller = "User", action="profil", userid = RouteParameter.Optional }

);

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.