0

I have the following javascript:

function foo()
{
  var someObject = $("#someTextbox").val();
  var contentType = 'application/x-www-form-urlencoded; charset=UTF-8;';
  AjaxRequest(someObject, 'html', 'post', '/ErrorCheck/SaveToFile', contentType, function(response)
  {
    //stuff
  }, function(error)
  { });
}

function AjaxRequest(data, dataType, type, url, contentType, success, error, args)
{
  try
  {
    var useFD = false;
    var form = new FormData();
    if (type.toUpperCase() == 'POST')
    {
      if (contentType && contentType.indexOf('application/x-www-form-urlencoded; charset=UTF-8;') === 0)
      {
        form.append("MyData", JSON.stringify(data));
        url = antiForgeryToken.add(url);
        useFD = true;
      }
    }

    $.ajax(
    {
      processData: useFD ? false : true,
      mimeType: useFD ? "multipart/form-data" : "",
      async: args.async,
      cache: args.cache ? true : false,
      data: useFD ? form : data,
      dataType: dataType,
      type: type,
      url: url,
      contentType: contentType,
      traditional: true,
      headers:
      {
        '__RequestVerificationToken': antiForgeryToken.token() != false ? antiForgeryToken.token().val() : '',
        '__loginUserId': $('#hidLOGINUSERID').val()
      },
      beforeSend: function(request)
      { },
      success: function(data, textStatus, XMLHttpRequest)
      {
        try
        {
            success(data, textStatus, XMLHttpRequest);
        }
        catch (e)
        {}
      },
      error: function(XMLHttpRequest, textStatus, errorThrown) {},
      complete: function(XMLHttpRequest) {}
    });
  }
  catch (err)
  {}
}

In the above scenario, useFD is true.

Then in my ErrorCheck controller's SaveToFile method, I have the following:

public void SaveToFile()
{
    try
    {
        if (Request.Form.Count > 0)
        {
            //do stuff
        }
    }
    catch (Exception ex)
    {
        ElmahLogUtility.ErrorException(ex);
    }
}

However, Request.Form.Count is always zero. I got this solution from a question I asked a few months ago here. I accepted the solution there back in October and I know this code was working, however it didn't get to a testing environment until just recently and it is no longer working, not even in my local environment.

What am I doing incorrectly?

Community
  • 1
  • 1
sab669
  • 3,984
  • 8
  • 38
  • 75
  • Your code is working at my end.If possible can you share your demo project – Chintan Udeshi Feb 02 '17 at 04:38
  • @ChintanUdeshi Unfortunately I can't strip our application down enough to the point where I could provide a working sample. I made a few minor tweaks though and I started getting a `Maximum request length exceeded` exception, which was resolved by adding `executionTimeout="100000" maxRequestLength="214748364"` attributes to the `` element in my `web.config`... Maybe that's what got removed and caused it to stop working 3 months later :) – sab669 Feb 02 '17 at 13:19

0 Answers0