Himanshu Shirodkar
Himanshu Shirodkar

Reputation: 45

Change MVC Routes

I have hosted a ASP.NET MVC website on IIS 7.5. The problem is that the site name and controller name are same, due to this I have to enter the controller name twice.

I am not allowed to change the name of the site or controller. My current URL for eg.

local/home/home/action

but I have shared as

localhost/home/action

now I need to configure the application so that the application routes properly for

localhost/home/action

Upvotes: 2

Views: 4288

Answers (2)

Damon Jones
Damon Jones

Reputation: 49

If you are using MVC5 you can use the Route attribute. Like so:

[Route(“yourroot”)]
public ActionResult Index() { … }

More information can be found here Attribute Routing in ASP.NET MVC 5

Hope this helps

Upvotes: 2

Roman Marusyk
Roman Marusyk

Reputation: 24569

Try to add a new route to RouteConfig.cs before others routes like:

routes.MapRoute(
    name: "DefaultHome",
    url: "{action}/{id}",
    defaults: new { controller = "Home", id = UrlParameter.Optional }
);

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
...

Upvotes: 1

Related Questions