2

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?

5
  • 1
    Do you have a physical content folder on the site? I used to get that issue because I had a matching physical root folder that matched a controller. Commented Aug 30, 2016 at 12:34
  • 1
    See stackoverflow.com/a/24533925/1625737 Commented Aug 30, 2016 at 12:51
  • @haim770 you should add that as the answer because it does provide a solution for the OP. I had overlooked that option as a possible solution. Commented Aug 30, 2016 at 12:53
  • @Nkosi, If it does actually answer the question, then the entire post is duplicate. And although setting RouteExistingFiles to true will work, I don't think it's the way to go. Commented Aug 30, 2016 at 12:55
  • @haim770, understood and agree Commented Aug 30, 2016 at 12:56

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I knew it had to be something right in front of me but I did not think about the default content folder.
0

go to project properties select web tab change specific page

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.