2

I am getting the following error when debugging my header links.

Error Message

I have tried recreating my Index.cshtml (Empty and with Razor/HTML) and my ServicesController. If I browse to Services/Index explicitly then the page loads up correctly.

IE: localhost:58069/Services/ does not work but localhost:58069/Services/Index does

My other controllers are working correctly using the same structure and ActionLink helper.

Not working code:

public class ServicesController : Controller
{
    // GET: Services
    public ActionResult Index()
    {
        return View();
    }
}

Action Link HTML Helper for Services/Index

<li>@Html.ActionLink("Services", "Index", "Services")</li>

Working Code

public class HomeController : Controller
{
    // GET: Home/Index
    public ActionResult Index()
    {
        return View();
    }
}

Working Helper

<li>@Html.ActionLink("Welcome", "Index", "Home")</li>

Route Config

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

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

Tried the following SO solutions:

ASP MVC in IIS 7 results in: HTTP Error 403.14 - Forbidden

enter image description here

huysentruitw
  • 27,376
  • 9
  • 90
  • 133
Bryan Halterman
  • 315
  • 4
  • 10
  • You said when you navigate to Service/Index it loads, yet your controller is Services so the default folder structure should be Views/Services/Index.cshtml not Views/Service/Index.cshtml. – Landy Dec 26 '17 at 19:58
  • I fixed the spelling mistakes in my explanations. The View is in View/Services/Index.cshtml I'll add a photo as well. – Bryan Halterman Dec 26 '17 at 20:02

1 Answers1

4

This behavior is caused by the Services folder (below Scripts folder) you have in your project. When hosting in IIS, you should not have a file or folder with the same name as your ASP.NET route.

Ways to solve this:

  • routes.RouteExistingFiles = true; will let ASP.NET handle all the routing
  • Rename your Services folder or controller
  • Move Services to a separate library and remove the folder from the web project

I'd recommend the latter option as settings RouteExistingFiles to true would need additional research to double-check you're not opening any security holes and it cleans up your web project (a little bit of separation never hurts).

huysentruitw
  • 27,376
  • 9
  • 90
  • 133
  • Winner Winner Chicken Dinner, it was a namespace issue on my internal services... Where my namespace matched my controller name. Thank you very much sir! – Bryan Halterman Dec 27 '17 at 03:33
  • I ran into the same issue when creating a new environment and using IIS8. IIS7 worked fine with the services folder in place and not setting RouteExistingFiles. – jreed350z Jan 24 '18 at 19:55