ASP.net“ {Controller} /”返回403.14错误 [英] ASP.net "{Controller}/" returning 403.14 error

查看:176
本文介绍了ASP.net“ {Controller} /”返回403.14错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发的一个项目有一个奇怪的问题。问题在于指向特定URL // localhost:62168 / Images / Index的链接。我有链接到该URL的按钮,但是当访问 // localhost:62168 / Images /时,它将返回HTTP错误403.14-禁止的错误。参见下图:

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 /

不过,奇怪的是,当我准确输入URL( localhost:62168 / Images / Index)时,它会正确加载页面。参见下图:

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

localhost /图片/索引

我已经在网上进行了大量研究,我认为这可能是路由问题,因此下面我添加了我的代码 RouteConfig.cs文件。不幸的是,我是ASP.net和MVC的新手,对适当的路由过程也不了解。

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. 在web.config中添加 directoryBrowse enabled = true

  2. 正在运行命令提示符中的 C:\windows\Microsoft.NET\Framework64\v4.0.30319> aspnet_regiis.exe -i

  3. 通过IIS Express并注册IIS Express和ASP .net

我将非常感谢任何人都可以提供的帮助!

I would greatly appreciate any help that anyone can provide!

推荐答案

如果IIS在文件系统上找到与URL匹配的内容,它将尝试使请求短路。换句话说,假设您在文档根目录中有 Images 目录。因此,IIS将尝试访问此目录,而不是将请求传递给ASP.NET机械。由于您已禁用目录浏览,因此您会得到403。

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.

长短不一,您需要保持自己的ASP.NET MVC路由与物理上唯一的路由不同文档根目录。您可以将 Images 目录的名称更改为 img 之类的名称,或将其放在默认的父文件夹中 / Content / Images 。否则,您将需要更改控制器名称或创建到该控制器的自定义路由,而不是称为 / Images

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.

这篇关于ASP.net“ {Controller} /”返回403.14错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆