Ajax http 500 error Azure not on local

时间:2015-06-26 10:30:35

标签: ajax azure model-view-controller http-error

When running an ajax request I get an error message:

Failed to load resource: the server responded with a status of 500 (OK)

The problem is that the server error does not seem to occur. When I run the application on my local machine but with the azure database I don't get the error message. Only the published azure application generates this error. I have done remote debugging and even though the browser display this error the server keeps handling the request and some minutes later it finishes the request. As if there actually was not server error.

The server needs about 10 minutes to finish the request. I believe it has something to do with the fact that the request it very long (because it works on smaller databases). I know azure has restrictions on CPU time on app service level free but I switched up to basic (no cpu time restrictions) so that should not be a problem. The request is very sql intense (about 20k sql queries).

Ajax call:

  $.ajax({
  async: true,
  cache: false,
  type: "POST",
  url: FooURL,
  contentType: 'application/json',
  dataType: "json",
  data: JSON.stringify(null),
  success: function (error_message) {
    $("#FooBar").removeClass("loading");
  },
  error: function(jqXHR, textStatus, errorThrown) {
  console.log(textStatus, errorThrown);
  }
});

Controller:

  [Authorize]
  [RequireHttpsAttribute]
  public class FooController : Controller
  {
    private FooBarModel foobarModel = new FooBarModel();

    public ActionResult UpdateFooBarModel()
    {
      foobarModel.UpdateModel();
      return Json("Success");
    }

1 个答案:

答案 0 :(得分:0)

天蓝色中显然存在空闲超时,其描述为here。默认值设置为4分钟,如果在VM上运行应用程序,则最多可配置为30分钟。我通过在数据库中创建一个表来存储当前的请求状态来解决它。

表:

CREATE TABLE [dbo].[MyTable] (
[UpdateNo] INT IDENTITY (1, 1) NOT NULL,
[AllDone]  BIT DEFAULT ((0)) NOT NULL,
CONSTRAINT [MyTable$PrimaryKey] PRIMARY KEY CLUSTERED ([UpdateNo] ASC)

);

我没有直接调用该方法,而是创建一个任务并返回更新状态行的id。

public ActionResult UpdateFooBarModel()
{
  int id = foobarModel.StartUpUpdate(); //Creates the status row 
  Task.Run(() => foobarModel.UpdateModel(id));
  return Json(id);
}

public ActionResult GetUpdateStatus(int UpdateNo)
{
  bool status = foobarModel.GetUpdateStatus(UpdateNo);
  return Json(status);
}

Ajax电话:

function check_status(StatusId) {
$.ajax({
  async: true,
  cache: false,
  type: "POST",
  url: GetUpdateStatusURL + "/?UpdateNo=" + StatusId,
  contentType: 'application/json',
  dataType: "json",
  success: function (StatusDone) {
    if (StatusDone == true) {
      console.log("Update done!");
      $("#FooBar").removeClass("loading");
    } else {
      console.log("Not done!")
      setTimeout(function () {
        check_status(StatusId);
      }, 5000); //Check every 5 seconds
    }
  },
  error: function (jqXHR, textStatus, errorThrown) {
    console.log(textStatus, errorThrown);
  }
});

}