how to route the controller to a different name

Total Post:412

Points:2888
 1252  View(s)
Ratings:
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
{
    //[Route("api/mobile/pswdrec/")]
    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

    Points:2694
    Re: how to route the controller to a different name

    Hi Pravesh, 


    try this:

    config.Routes.MapHttpRoute(

                    name: "MyCustomRouteApi",

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

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

                );

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!