4

We have a very strange problem which we have yet to be able to diagnose. Our application has a number of specific ASP.NET MVC actions which fail because a required parameter is missing:

The parameters dictionary contains a null entry for parameter 'myVariable' of non-nullable type... etc

Each of these is some sort of HTTP POST, and thus we expect to see form data. In some cases there should be over a dozen variables.

We use ELMAH to collect errors in the web application, and via this tool you can typically see the actual form data which is posted during a request which fails. However in these specific errpr when there should be several variables the entire form is missing!

We simply cannot reproduce this on-demand. However with the volume of traffic in our application we see these errors several dozen times a day. Users cannot reproduce the error either, and trying the same action in the web browser works a second time.

We're also not 100% sure where the data is lost. Is it in the web browser? Inside the IIS pipeline? Or is it ASP.NET MVC which dumps it? Totally unsure.

If anyone can help us troubleshoot and/or diagnose this problem it would be greatly appreciated.

Update 1: We've discovered that the content length as specified in the HTTP Headers is of a size that suggests that there is some content in the request. However the forms collection on the request is empty (as per ELMAH). So we've added some additional logging to trace the actual length of the content received and the content itself.

Update 2: We have discovered that while the CONTENT_LENGTH HTTP Header is of the correct size (for a similar requests), the content itself is missing. The stream contains 0 bytes.

We've also be able to narrow down the problem to Internet Explorer, we can't seem to get it to happen with other browsers.

We've been able to sometimes recreate the problem by causing several overlapping AJAX requests in the browser, and then either refreshing or redirecting. It's almost as if Internet Explorer is closing the connection before completely writing out the stream buffer.

We have not been able to trace this with Fiddler. Using Fiddler, it appears it is impossible to recreate the specific situation.

Update 3: Everything we've seen can be explained by this: Why does Internet Explorer not send HTTP post body on Ajax call after failure?

Community
  • 1
  • 1
Joseph Daigle
  • 47,650
  • 10
  • 49
  • 73

3 Answers3

1

This might be a bit of a guess, but is it possible that your action does not have the [HttpPost] restriction on it, so that somehow users are getting to it via a GET rather than a POST?

I've had something similar happen in my app where users try POST to a URL, but their FormsAuthentication ticket has expired, so they get redirected to the login page. But because the login page has the "ReturnUrl" parameter passed to it, once they login they are redirected back to the page they are meant to be POSTing to originally, but this time with a GET. This would cause the error you describe, as obviously none of the POST data is present any more. As I say, bit of a guess...

JonoW
  • 14,029
  • 3
  • 33
  • 31
  • Some, but not all of the actions have [HttpPost] restriction. Additionally, the error log is indicating that it is indeed an HTTP POST, not a GET. But this is good advice anyway. – Joseph Daigle May 20 '11 at 16:54
  • Ah pity, not sure what else to suggest, hope you figure it out though :) – JonoW May 20 '11 at 21:26
0

The error message you posted doesn't seem like there's anything wrong with the form. To me it looks like a routing issue so here's what I would ask:

  • Is the POST going to the correct controller/action? For example, check to make sure its going to the correct area (if you are using it)
  • Does the method signature of the controller action, especially the myVariable parameter match the route pattern? In other words, its possible your action expects myVariable but the Url calling it either has no 'myVariable' or is misspelled, etc.
  • It is triggering the correct action since that is what we receive the exception on. The problem is that the forms collection on the request appears to be empty. We see this a) because ASP.NET MVC cannot find the parameter and b) our error logging reports the forms collection is empty. However we've recently discovered that the CONTENT_LENGTH header in the HTTP request is non-zero, suggesting that there should be /some/ content we are receiving. – Joseph Daigle May 24 '11 at 00:53
  • Also, it works 99.5% of the time. And you can retry the same user action and it works. It's just that < 1% of the time which it seems to fail. – Joseph Daigle May 24 '11 at 00:54
0

The source of the problem can be explained by this: Why does Internet Explorer not send HTTP post body on Ajax call after failure?

Update: It turns out that our specific symptoms seemed to be tied to use of jQuery. After upgrading, the problem has eventually gone away.

Community
  • 1
  • 1
Joseph Daigle
  • 47,650
  • 10
  • 49
  • 73
  • 1
    Can you give some details on what the problem with jQuery was, or at least the version number? – polm23 May 22 '13 at 07:57