Reputation: 3707
I have a really weird one to me that I can't figure out. I'm not an expert with routing but this should be straight forward.
I have a controller called NewsletterController and it has the typical Index ActionResult. If I run my site in debug mode and use a link to go to my Newsletter section I get a 403.14 Forbidden
message. If I add the "Index" to the route then it will go to the ActionResult just fine. I have other controllers setup with a Index ActionResult the exact same way and work just fine. It's something about this specific controller that is not working and I just don't see what the problem is.
This is my controller code:
public class NewsletterController : Controller
{
public ActionResult Index()
{
var vm = new NewsletterViewModel();
...CODE REMOVED FOR SPACE
return View(vm);
}
}
This is the action link from my _Layout.cshtml:
@Html.ActionLink("Newsletters", "Index", "Newsletter", null, new { @class = "nav-link" })
My Routing class
public class RouteConfig
{
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 }
);
}
}
If I go here I get the 403.14 Forbidden
message.
http://localhost:59571/Newsletter/
If I add the Index to the route it goes to the page.
http://localhost:59571/Newsletter/index
Upvotes: 2
Views: 618
Reputation: 247008
403.14 Forbidden
typically occurs when you try to browse to a directory on the site and the Web site does not have the Directory Browsing feature enabled, and the default document is not configured.
In this case you have an actual Newsletter
folder which is conflicting with the default route of the NewsletterController
when you try to call
http://localhost:59571/Newsletter/
It will try to return the actual content of that folder which will fail if the feature is not enabled.
Either remove or rename the folder to something that does not conflict with any of your controller names
Upvotes: 5