Is it possible to call a web service from GLOBAL.ASAX and store the 'data' json structure in a "global" struct variable?

StackOverflow https://stackoverflow.com/questions/21858178

  •  13-10-2022
  •  | 
  •  

سؤال

We page a .Net page which makes 5 AJAX calls (such as the one below) and in order to speed up a little bit we would like to move some of these calls to the Global.asax. Is it possible to call it from the Application_Start event? Also, how do I store the "data" structure in a "global" variable so that I can loop through the data json structure in order to populate my dropdownbox "jqStatusID" below?

function GetStatusList(async) {
  $.ajax
  ({
      async: async
    , url: "svc/Job.svc/JobView/GetStatusList"
    , cache: false
    , dataType: "json"
    , error: function (jqXHR, textStatus, errorThrown) { }
    , success: function (data, textStatus, jqXHR) {
        $.each(data, function (key, value) {
            JobInstanceStatus[JobInstanceStatus.length] = {
                StatusID       : value.StatusID,
                Name           : value.Name
            };
            $(jqStatusID).append($("<option></option>").attr("value", value.StatusID).text(value.Name));
        });
        $(jqStatusID).multiselect('refresh');
    }
  });
}

Thank you

هل كانت مفيدة؟

المحلول

First of all, jQuery is a client side technology, and thus cannot be used on the server side. Second, why make an AJAX request to your own server? You can just access the data directly and cache it.

If you want to make the request in Application_Start, they it is probably application-wide data and not user specific. In this case, you should use Cache and not session.

If you would like to make the calls in parallel, you can look in to server-side async calls using the Task Parallel Library, which would be a much better fit for the situation you are describing.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top