how to route the controller to a different name

Total Post:412

 1325  View(s)
Rate this:

Have a really basic thing to do - I need to expose a post API such as mobile/api/pswdrec which I wanna bind to my PasswordController to avoid that dull name. 

It's a webapi with areas and I'm trying both Attribute Routing and MapHttpRoute. neither works so far.

public class PasswordController : MobileApiControllerBase
    public RestResponseMessage Post(UserCredentialsModel credentials)
        return RestResponseMessage.OK();

Checked the client side and the requests are proper json requests. It's starting to work when I simply change the name of the controller to PswdrecController. 

Is there any other way to "rename" the controller?

  1. Post:378

    Re: how to route the controller to a different name

    Hi Pravesh, 

    try this:


                    name: "MyCustomRouteApi",

                    routeTemplate: "api/{controller}/{id}",

                    defaults: new { controller = "mobile", action = "pswdrec", id = RouteParameter.Optional}