ASP.NET页面webmethod AJAX调用请求超时
我在asp页面上有webmethodASP.NET页面webmethod AJAX调用请求超时,asp.net,ajax,webmethod,Asp.net,Ajax,Webmethod,我在asp页面上有webmethod [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public static string MyMethod(string requestObject) { // here is operation that takes approximately 200 - 300 second } 页面上还有一个AJAX方法
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string MyMethod(string requestObject)
{
// here is operation that takes approximately 200 - 300 second
}
页面上还有一个AJAX方法
jQuery.ajax({
url: 'MyPage.aspx/MyMethod',
type: 'POST',
contentType: "application/json",
dataType: 'json',
data: somedata,
timeout: 300000,
success: function (response) {
some handler
}
});
当我尝试调用这个ajax方法时,我得到“System.Web.HttpException:Request timed out”
我试图将executionTimeout=“300”添加到web.config中的元素。
问题解决了。但据我所知,这将增加所有应用程序的超时时间。
我不想这样做。
有没有更合适的方法来修复超时异常?
executionTimeout参数是为所有请求设置超时,还是仅为异步请求设置超时?您是否尝试过
Server.ScriptTimeout
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string MyMethod(string requestObject)
{
HttpContext.Current.Server.ScriptTimeout = 300;
// here is operation that takes approximately 200 - 300 second
}
executionTimeout参数是否为所有请求或
只针对异步请求
这适用于不设置自己超时的所有请求。
从服务器的角度来看,同步或异步请求之间没有http差异。试试这个Hi!抱歉,我无法在我的webmethod中使用“服务器”。方法是静态的,因此此属性不可用。@TarasLviv抱歉没有注意到该静态。我编辑了我的答案。非常感谢!这正是我需要的。