【问题标题】:HTTP Error 404.15 -Not FoundHTTP 错误 404.15 - 未找到
【发布时间】:2017-07-11 05:54:59
【问题描述】:

请求过滤模块配置为拒绝查询字符串过长的请求。

我遇到了上述错误,我几乎尝试了所有方法,但没有运气

我的项目是 Visual Studio 2013 上的 MVC4

我确定的事情是正确的并且已经尝试过了。

  • 在我的类中没有 [Authorize] Attr 与 [AllowAnonymous] Attr。
  • 我在配置文件中添加了 maxQueryStringLength="32768" maxUrlLength="65536"
  • 我已添加 -->
  • 我在控制器中的操作日志中有 [AllowAnonymous] attr。

  • 在 Visual Studio 上以调试模式或不以调试模式运行应用程序时没有问题。

  • 这是我的溃败配置 路线.MapRoute( 名称:“默认”, url: "{controller}/{action}/{id}", 默认值:新 { 控制器 =“主页”,操作 =“索引”,id = UrlParameter.Optional } );

  • 这是我在网络服务器上遇到的错误

【问题讨论】:

    标签: c# visual-studio asp.net-mvc-4 iis-7.5


    【解决方案1】:

    正如错误消息告诉你的那样

    请求过滤模块配置为拒绝查询字符串过长的请求。

    在截图中你可以清楚的看到returnUrl参数很大。

    所以有解决办法

    1. 清除控制器方法[HttpPost] Login();中的returnUrl参数

    2. 将以下内容添加到您的web.config

    web.config

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

    在您的情况下,请务必使用解决方案 1。这只是您的代码中的一个错误,无需触及 IIS 或其他配置文件即可轻松修复。

    有关请求查询字符串限制的更多信息,请参阅this post

    【讨论】:

    • 感谢您的回复。我已将 添加到 Web.config 但我收到另一个错误 The length此请求的查询字符串的个数超过了配置的 maxQueryStringLength 值。
    • @Frank 为什么?修复控制器中的代码会简单得多
    • 如何在控制器上解决这个问题?谢谢@Smartis
    • @Frank 在你的控制器中必须是一个类似[HttpPost] Login(); 的方法,它应该返回一个带有参数returnUrlAction。不要每次都向这个参数添加一些东西,而是清除该值。这应该只存储最后一个 returnUrl 值,并且不应该破坏您请求的 URL。
    • 我能够解决这个问题,感谢您的所有帮助。
    【解决方案2】:

    我遇到了同样的问题,我用 POST 替换了 GET 方法,它起作用了。

    【讨论】:

    • 当然可以。 POST 比 GET 有更多空间
    【解决方案3】:

    插入/更新 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>
    

    【讨论】:

      【解决方案4】:

      只需修改 web.config 添加

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

      也在下添加

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多