I am having a curious issue with one of my projects in development. The issue is with links to a certain URL "//localhost:62168/Images/Index". I have buttons linking to that URL but when "//localhost:62168/Images/" is accessed it returns a HTTP Error 403.14 - Forbidden error. See the below Image:
Oddly enough though, when I enter the URL exactly ("localhost:62168/Images/Index") it loads the page properly. See the below Image:
I've done plenty of research online and I believe it may be an issue with routing so below I've added the code of my "RouteConfig.cs" file. Unfortunately, I am new to ASP.net and MVC and not knowledgeable on proper Routing procedures:
using System.Web.Mvc;
using System.Web.Routing;
namespace ReedHampton
{
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 }
);
}
}
}
I've also tried multiple other "solutions" presented in other online forums to no avail. These include:
- Adding "directoryBrowse enabled="true" " to web.config
- Running "C:\windows\Microsoft.NET\Framework64\v4.0.30319> aspnet_regiis.exe -i" in Command Prompt
- Going through IIS Express and registering IIS Express and ASP.Net
I would greatly appreciate any help that anyone can provide!
IIS will attempt to short-circuit the request if it finds something on the filesystem that matches the URL. In other words, I'd assume you have an
Images
directory in your document root. Therefore, IIS will attempt to hit this directory, rather than pass the request on to the ASP.NET machinery. Since you've disabled directory browsing, you get a 403.Long and short, you need to keep your ASP.NET MVC routes unique from what you have physically in your document root. You could change the name of the
Images
directory to something likeimg
, or put it in a parent folder like the default of/Content/Images
. Otherwise, you'll need to change your controller name or create a custom route to that controller not called/Images
.