Terry H
Terry H

Reputation: 89

How to set up default route in MVC5

I am having troubles understanding the default route setup in MVC5. I have this code in the RouteConfig.cs file

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        name: "Content",
        url: "content/{action}",
        defaults: new { controller = "Content", action = "Index" }
    );

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

When I go to www.mydomain.com/content/index it works fine. However if I go to www.mydomain/content I get an error 403.14 Forbidden. I understand this is a newbie question but what am I missing? Should it not default to the index controller?

Upvotes: 2

Views: 3176

Answers (2)

hadi.sh
hadi.sh

Reputation: 129

go to project properties select web tab change specific page

Upvotes: 0

Nkosi
Nkosi

Reputation: 247561

If you are using default Asp.Net MVC5 project template then there already exists a physical folder called content in the project and by extension, the root of the site.

If you try to browse to the content folder IIS will give you that error. The request would not reach the route table.

Consider renaming either the folder or the controller. Each would have their own knock on effect depending on the requirements of your project.

Upvotes: 3

Related Questions