1

On my IIS server, I'm getting a warning message logged in the server's Application Event Log on a particular variety of incoming HTTP request with a long URL. Despite the warning message, ASP.NET MVC does correctly handle the request and return the expected response back to the client.

The event log message warning message includes the following text:

Event code: 3005 
Event message: An unhandled exception has occurred. 

...

Process information: 
    Process name: w3wp.exe 

....

Exception information: 
    Exception type: HttpException 
    Exception message: The length of the URL for this request exceeds the configured maxUrlLength value.
    at System.Web.HttpRequest.ValidateInputIfRequiredByConfig()
    at System.Web.HttpApplication.PipelineStepManager.ValidateHelper(HttpContext context)

Additional property/value information for the event log warning message:

Source: ASP.NET 4.0.30319.0
Event ID: 1309

Again, in this case the incoming HTTP request is ultimately succeeding, so unlike similar questions my question here is not how to successfully increase the max URL length for incoming requests on my server.

Rather, my question is: Given that my request is succeeding, can I prevent this (apparently spurious) warning message from being logged to my Application event log (adding noise to the log that may obscure other, "real" warnings)?

More details

This behavior (long HTTP request succeeds; warning message written to application event log) is reproducible both on my local workstation PC running Windows 10 and IIS 10, and on my production server running Windows Server 2008 R2 and IIS 7.5.

The project is being built with target framework: .NET Framework 4.5.1. (Update: The error still reproduces after rebuilding my project to target .NET Framework 4.6.1.)

The URLs that trigger the warning message to be written are long URLs (approximately 500 characters in length) of the form (for example):

https://myserver.example.com:443/api/MyDataRequestRoute/1862241,2146171,1998613,1916341,2150391,2067889,749865,2167130,1861707,1914448,668472,2170269,2162087,2024193,1857969,1869304,2162128,1980539,992479,1347745,1958431,282062,1925128,2147391,2153550,1187318,2039442,441327,1298384,2153556,1526985,1893085,2144727,2144288,1582412,2142540,2170281,1183488,1865249,1348332,1322007,2170282,2170283,1750061,2098502,1915955,905164,1353083,2099151,1347806,2160403,2147200,1191371,1347921,1909967,2017687,2012831 

The URL is mapped to an ASP.NET MVC Controller method of the form:

[HttpGet]
[Route("MyDataRequestRoute/{commaSeparatedPropertyIDs}", Name = "MyDataRequestRoute")]
public HttpResponseMessage MyDataRequestRoute(string csv)
{
    string xmlResult = // Code to build result based on the specified csv...

    return new HttpResponseMessage()
    {
        Content = new StringContent(xmlResult, Encoding.UTF8, "text/xml")
    };
}

In order to get these long URLs working, I previously made a few configuration changes to my application and server, specifically:

  • Set an UrlSegmentMaxLength value of 32766 in the server's Windows registry, per this answer.
  • Set attributes of the httpRuntime element in my "Api" project's web.config file:

<httpRuntime targetFramework="4.5" maxRequestLength="131072" maxUrlLength="32766" maxQueryStringLength="32766" />

  • Set the maxAllowedContentLength attribute of the requestLimits element in the same web.config file:

<requestLimits maxAllowedContentLength="134217728" />

Community
  • 1
  • 1
Jon Schneider
  • 25,758
  • 23
  • 142
  • 170

0 Answers0