ilter
ilter

Reputation: 4079

Use just Controller name as route

I would like to access my NewsList route by that URL: http://domain.com/news

I have three routes like:

routes.MapRoute(
    name: "NewsList",
    url: "News",
    defaults: new { controller = "News", action = "List" }
);

routes.MapRoute(
    name: "NewsDetail",
    url: "{controller}/{action}/{title}/{id}",
    defaults: new { controller = "News", action = "Details", title = "", id = 0 }
);

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

I can use the Default and NewsDetail routes with no problems, but NewsList route cannot be accessed with the URL I provided below with the current configuration. When I try to access the NewsList route, I need to use the URL: http://domain.com/news/list.

EDIT: If I use http://domain.com/news, I get a HTTP Error 403.14 - Forbidden error on the screen.

Is it possible to ignore the action in this case?

Upvotes: 0

Views: 259

Answers (1)

Chris Pratt
Chris Pratt

Reputation: 239220

Make sure there's not a "news" directory in your project. If there is, that will take precedence and you'll get a 403 for attempting a directory listing.

Upvotes: 1

Related Questions