0

I have the new .NET WebAPI up and running and I am trying to add a new route to my project so that I can see the SettingsController in action. I have added my route to the Global.asax file within the RegisterRoutes method but I receive a 404 error when I try and browse to: sampleUrl:12345/settings/index. I am able to see: sampleUrl:12345/home/index without issue.

Global.asax

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

    routes.MapHttpRoute(
        name: "DefaultApi",
        routeTemplate: "api/{controller}/{id}",
        defaults: new { id = RouteParameter.Optional }
    );

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

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

Do I need to have an ActionResult Index() in my SettingsController?

1 Answer 1

2

Your settings route is redundant. What you are probably missing is the index method in settings controller.

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

3 Comments

OK, so remove that route for Settings from Global.asax. I do have a folder named Settings in my Views folder and that folder has an Index.cshtml file in it. Is that what you mean?
I have a ProductsController that is executed by default. This works without issue. There is not a Index method in the ProductsController. There is one in the HomeController however. I am using the WebAPI starter project.
I don't have Visual Studio installed on this laptop, but if you have 5 minutes, scan thru this article

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.