4

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

things I have made sure are correct and tried.

  • There is no [Authorize] Attr on my classes with [AllowAnonymous] Attr.
  • I have added maxQueryStringLength="32768" maxUrlLength="65536" to in my config file
  • I have added -->
  • I have [AllowAnonymous] attr on my log on Actions in my controller.

  • I have no problem when I run the application in debug mode or without debug mode on Visual Studio.

  • here is my rout config routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } );

  • this is the error I am getting on the web server

enter image description here

Frank
  • 131
  • 3
  • 3
  • 15

6 Answers6

9

Insert/Update web.config file as like sample below

<configuration>
   <system.webServer>
       <security>
          <requestFiltering>
             <requestLimits maxQueryString="3000" maxUrl="1000" />
          </requestFiltering>
       </security>
   </system.webServer>
   <system.web>
       <httpRuntime maxQueryStringLength="32768" maxUrlLength="65536"/>
   </system.web>
</configuration>
Sedat Kumcu
  • 2,191
  • 1
  • 17
  • 13
5

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.

So there are to solutions

  1. Clear your returnUrl Parameter in your Controller Method [HttpPost] Login();

  2. Add the following to your 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.

See this post for more information about Request Query String Limit.

Community
  • 1
  • 1
  • Thank you for your reply. I have added the to Web.config but I am getting another error The length of the query string for this request exceeds the configured maxQueryStringLength value. – Frank Feb 21 '17 at 15:06
  • @Frank Why? Fixing the Code in your Controller, would be much simpler – Smartis has left SO again Feb 21 '17 at 15:08
  • How would you fix this on the controller ? thank you @Smartis – Frank Feb 22 '17 at 14:53
  • 1
    @Frank In your Controller must be a Method like this `[HttpPost] Login();` which should return a `Action` with the parameter `returnUrl`. Instead of adding every time something to this parameter, clear the value. This should only store the last `returnUrl` value and shouldn't blow up your requested URL. – Smartis has left SO again Mar 06 '17 at 09:02
  • I was able to fix this thank you for all of your help. – Frank Mar 30 '17 at 16:49
3

just modify the web.config add

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

also add under <system.web>

<httpRuntime maxQueryStringLength="32768" maxUrlLength="65536"/>
Jamal Qudah
  • 81
  • 1
  • 3
1

if you have already scaffolding the identity login , just add [AllowAnonymous] in the page (behind code) login, like this :

[AllowAnonymous]
public class LoginModel : PageModel { ....... }

0

I had the same problem, I replaced GET method with POST and it worked.

Mehdi Souregi
  • 3,153
  • 5
  • 36
  • 53
0

Put [AllowAnonymous] in the Login Page(for Razor Project like mine) or the View's Controller(for MVC - I imagine).

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). 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.

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(); });