ASP.net “{Controller}/” returning 403.14 error

感情迁移 提交于 2019-12-24 08:29:47

问题


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:

localhost//Images/

Oddly enough though, when I enter the URL exactly ("localhost:62168/Images/Index") it loads the page properly. See the below Image:

localhost/Images/Index

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:

  1. Adding "directoryBrowse enabled="true" " to web.config
  2. Running "C:\windows\Microsoft.NET\Framework64\v4.0.30319> aspnet_regiis.exe -i" in Command Prompt
  3. Going through IIS Express and registering IIS Express and ASP.Net

I would greatly appreciate any help that anyone can provide!


回答1:


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 like img, 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.



来源:https://stackoverflow.com/questions/44932387/asp-net-controller-returning-403-14-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!