Home > DeveloperSection > Forums > how to route the controller to a different name
Pravesh Singh

Total Post:411

Points:2881
Posted on    September-20-2014 12:20 AM

 ASP.NET MVC .NET  ASP.NET MVC 
Ratings:


 1 Reply(s)
 679  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

{

    //[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?



Sumit Kesarwani

Total Post:378

Points:2694
Supported
Posted on    September-20-2014 12:23 AM

Hi Pravesh, 

try this:

config.Routes.MapHttpRoute(

                name: "MyCustomRouteApi",

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

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

            );


Don't want to miss updates? Please click the below button!

Follow MindStick