简体   繁体   English

HTTP 错误 404.15 - 未找到

[英]HTTP Error 404.15 -Not Found

The request filtering module is configured to deny a request where the query string is too long.请求过滤模块用于拒绝查询字符串过长的请求。

I am having above error, and I have been trying almost everything but no luck我有上述错误,我几乎尝试了所有方法,但没有运气

My Project is MVC4 on Visual Studio 2013我的项目是 Visual Studio 2013 上的 MVC4

things I have made sure are correct and tried.我确定的事情是正确的并且已经尝试过了。

  • There is no [Authorize] Attr on my classes with [AllowAnonymous] Attr.我的班级没有 [AllowAnonymous] Attr 的 [Authorize] Attr。
  • I have added maxQueryStringLength="32768" maxUrlLength="65536" to in my config file我在我的配置文件中添加了 maxQueryStringLength="32768" maxUrlLength="65536"
  • I have added -->我已经添加了 -->
  • I have [AllowAnonymous] attr on my log on Actions in my controller.我在我的控制器中登录操作时有 [AllowAnonymous] attr。

  • I have no problem when I run the application in debug mode or without debug mode on Visual Studio.当我在 Visual Studio 上以调试模式或不使用调试模式运行应用程序时,我没有任何问题。

  • here is my rout config routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } );这是我的路由配置 routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter 。选修的 } );

  • this is the error I am getting on the web server这是我在网络服务器上遇到的错误

在此处输入图像描述

Insert/Update web.config file as like sample below插入/更新 web.config 文件,如下例所示

<configuration>
   <system.webServer>
       <security>
          <requestFiltering>
             <requestLimits maxQueryString="3000" maxUrl="1000" />
          </requestFiltering>
       </security>
   </system.webServer>
   <system.web>
       <httpRuntime maxQueryStringLength="32768" maxUrlLength="65536"/>
   </system.web>
</configuration>

As the error message tells you正如错误消息告诉您的那样

The request filtering module is configured to deny a request where the query string is too long.请求过滤模块用于拒绝查询字符串过长的请求。

At the screenshot you can clearly see that the returnUrl Parameter is huge.在截图中可以清楚地看到returnUrl参数很大。

So there are to solutions所以有解决办法

  1. Clear your returnUrl Parameter in your Controller Method [HttpPost] Login();清除控制器方法[HttpPost] Login();中的returnUrl参数;

  2. Add the following to your web.config :将以下内容添加到您的web.config

web.config网页配置文件

<system.webServer>
  <security>
    <requestFiltering>
      <requestLimits maxQueryString="*"/> <!-- Replace * with any number, which is required -->
    </requestFiltering>
  </security>
</system.webServer>

In your case go definitively with Solution 1. It's simply a bug in your Code and easily fixed without touching the IIS or other config files.在您的情况下,请明确使用解决方案 1。这只是您代码中的一个错误,无需触及 IIS 或其他配置文件即可轻松修复。

See this post for more information about Request Query String Limit.有关请求查询字符串限制的更多信息,请参阅此帖子

just modify the web.config add只需修改web.config添加

<configuration>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxQueryString="30000" maxUrl="10000" />  
</requestFiltering>
</security>
</system.webServer>
</configuration>

also add under <system.web>也在 <system.web> 下添加

<httpRuntime maxQueryStringLength="32768" maxUrlLength="65536"/>

if you have already scaffolding the identity login, just add [AllowAnonymous] in the page (behind code) login, like this:如果您已经搭建了身份登录脚手架,只需在页面(代码后面)登录中添加 [AllowAnonymous],如下所示:

[AllowAnonymous] [允许匿名]
public class LoginModel: PageModel {....... }公共类 LoginModel:PageModel {....... }

I had the same problem, I replaced GET method with POST and it worked.我遇到了同样的问题,我用 POST 替换了 GET 方法并且它起作用了。

Put [AllowAnonymous] in the Login Page(for Razor Project like mine) or the View's Controller(for MVC - I imagine).将 [AllowAnonymous] 放在登录页面(对于像我这样的 Razor 项目)或视图的控制器(对于 MVC - 我想)。

Perhaps you scaffolded the Login Page, thereby making it subject - as soon as you hit Login button - to your fallback policy* in your Program.cs (now in .NET 6.0, Startup.cs for earlier .NET).也许您搭建了登录页面的脚手架,从而使其在您点击登录按钮后立即受制于 Program.cs 中的后备策略*(现在在 .NET 6.0 中,Startup.cs 用于更早的 .NET)。 Your fallback policy forbids any Page(view) without a policy, and since you have no policy in the login page, as soon as you hit the login it calls that view, and you get the error.您的回退政策禁止任何没有政策的页面(视图),并且由于您在登录页面中没有政策,一旦您点击登录它就会调用该视图,并且您会收到错误消息。 I'm not sure that I understand why it isn't a nice error.我不确定我是否理解为什么这不是一个好错误。 Perhaps because it tries a hundred times to put that URL in and therefore it implies that in the 25252525225252522 etc and so forth message.可能是因为它尝试了一百次将该 URL 放入,因此它暗示在 25252525225252522 等消息中。

Luckily I was helped pinpointing the error because my app worked fine logging in and out without the fallback policy, but it was exactly that fallback policy that caused error.幸运的是,有人帮助我查明了错误,因为我的应用程序在没有回退策略的情况下可以正常登录和注销,但正是回退策略导致了错误。

  • By fallback policy, I refer to:通过后备政策,我指的是:

    builder.Services.AddAuthorization(options => { options.FallbackPolicy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build(); }); builder.Services.AddAuthorization(options => { options.FallbackPolicy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build(); });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM