ASP.NET页面的WebMethod AJAX调用请求超时

编程入门 行业动态 更新时间:2024-10-28 20:27:48
本文介绍了ASP.NET页面的WebMethod AJAX调用请求超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的webmethod的ASP页

[WebMethod的]     [ScriptMethod(ResponseFormat = ResponseFormat.Json)     公共静态字符串的MyMethod(字符串requestObject)     {         //这里的操作,需要大约200 - 300秒     }

也有是页面上的AJAX方法

jQuery.ajax({         网址:MyPage.aspx /的MyMethod,         键入:POST,         的contentType:应用/ JSON         数据类型:JSON,         数据:somedata,         超时:300000,         成功:函数(响应){             一些处理程序         }     });

当我试图把这种阿贾克斯方法得到System.Web.HttpException:请求超时

我尝试添加executionTimeout =300为元素在web.config中。 而问题解决了。但据我了解,这将增加超时的所有应用程序。 我不想这样做。 有没有更合适的方式来解决超时异常? 又请问executionTimeout参数设置超时时间,所有请求,或只为异步请求?

解决方案

您是否尝试过 Server.ScriptTimeout ?

[WebMethod的] [ScriptMethod(ResponseFormat = ResponseFormat.Json) 公共静态字符串的MyMethod(字符串requestObject) {     HttpContext.Current.Server.ScriptTimeout = 300;     //这里的操作,需要大约200 - 300秒 }

  

和做executionTimeout参数设置超时时间,所有请求或   只是异步请求?

这是用于不没有设置自己的超时的所有请求。 从服务器的角度来看,有一个同步或异步请求之间没有差别的http

I have webmethod on asp page

[WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public static string MyMethod(string requestObject) { // here is operation that takes approximately 200 - 300 second }

Also there is an AJAX method on page

jQuery.ajax({ url: 'MyPage.aspx/MyMethod', type: 'POST', contentType: "application/json", dataType: 'json', data: somedata, timeout: 300000, success: function (response) { some handler } });

When I try to call this ajax method I get 'System.Web.HttpException: Request timed out.'

I tried to add executionTimeout="300" to element in web.config. And issue is resolved. But as I understand this will increase timeouts for all application. I don't want to do this. Is there a more proper way to fix timeout exception? And does executionTimeout parameter set timeout for all requests or just for async requests?

解决方案

Have you tried 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 }

And does executionTimeout parameter set timeout for all requests or just for async requests?

This is for all requests which do no set their own timeout. From the server point of view, there is no http difference between a sync or async request.

更多推荐

ASP.NET页面的WebMethod AJAX调用请求超时

本文发布于:2023-11-24 22:31:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627133.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:页面   NET   ASP   WebMethod   AJAX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!