中止异步 Web 服务调用并重定向到另一个 URL (ASP.NET Ajax)

发布于 2024-07-29 11:05:42 字数 1903 浏览 6 评论 0原文

在我的网络应用程序中,我有一个从代码隐藏生成并绑定到转发器控件的链接列表。 单击链接会打开一个弹出窗口,其中除了显示一些数据外,还会对 WCF 服务进行异步调用(通过 JavaScript 代理)。 此服务进而调用另一个可能需要很长时间才能响应的第三方 Web 服务。 我正在使用 IE6,这是不可避免的要求。

现在,如果用户决定不等待调用完成而只是关闭弹出窗口,我会在 onunload 时中止此服务。 问题是,如果用户立即单击转发器中的另一个链接,新的弹出窗口将打开,但不会加载页面(不会转到提供的 URL),直到上一个异步调用完成为止(我已经验证了这一点)通过提琴手)。 有趣的是,这只发生在同一域内的链接上。 如果我将其中一个 popus 的链接更改为 www.google.com,则窗口将打开并按预期转到正确的网址。 但是,对于在我自己的域内带有链接的弹出窗口(在关闭未完成请求的弹出窗口后立即打开),它会等到上一个请求完成后再加载 url。

我已经验证了中止回调的正确方法,并且 abort 确实正确触发。 我还知道我只能中止客户端调用,而不能中止服务器端调用,而且我不关心它。 我唯一的要求是浏览器加载下一个链接,无论之前的异步响应如何。

//Method to Call Service:

    function GetData(Id) {

            //call the service

            Sys.Net.WebRequestManager.add_invokingRequest(On_InvokingRequest);

            var service = new WrapperService();
            service.GetData(Id, handleSuccess, handleError, null);

            Sys.Net.WebRequestManager.remove_invokingRequest(On_InvokingRequest);
        }

//method to get the current requests abort executor
function On_InvokingRequest(executor, eventArgs) {
        var currentRequest = eventArgs.get_webRequest();
        abortExecutor = currentRequest.get_executor();
    }

//abort service on unload
function unload() {
        if (abortExecutor != null) {
            abortExecutor.abort();
        }
    }

背景的有用/类似链接:

浏览器等待 ajax 调用完成甚至在中止后已被调用 jquery 中止-an-asp-net-web-service-asynchronous-call< /a> 取消- ajax-web-service-call

有人遇到过这个吗? 它让我发疯! 任何帮助将不胜感激。

In my webapp, I have a list of links generated from code-behind and bound to a repeater control. Clicking on a link opens a popup window, where, along with displaying some data, an asynchronous call to a WCF Service is made (through a javascript proxy). This service in turn calls another third party web service that might take a long time to respond. I am working with IE6, thats a unavoidable requirement.

Now, I abort this service on onunload if the user decides to not wait for the call to complete and just closes the popup window. The problem is, if the user clicks another link from the repeater immediately after, the new popup window opens but doesn't load the page (doesn't go to the supplied URL) till the previous asynchronous call has completed (I have verified this through Fiddler). Interestingly, this only happens for links within the same domain. If I change the link for one of the popus to, say, www.google.com, then the window opens and goes to the correct url as intended. But, for popups with links within my own domain, which are opened immediately after a popup window with an unfinished request was closed, it waits till the previous request completes before loading the url.

I have verified the correct way to abort a callback and abort does fire properly. I also know that I can only abort my client side call, and not the server side call and I don't care about it. My only requirement is that the browser load the next link regardless of the previous asynchronous response.

//Method to Call Service:

    function GetData(Id) {

            //call the service

            Sys.Net.WebRequestManager.add_invokingRequest(On_InvokingRequest);

            var service = new WrapperService();
            service.GetData(Id, handleSuccess, handleError, null);

            Sys.Net.WebRequestManager.remove_invokingRequest(On_InvokingRequest);
        }

//method to get the current requests abort executor
function On_InvokingRequest(executor, eventArgs) {
        var currentRequest = eventArgs.get_webRequest();
        abortExecutor = currentRequest.get_executor();
    }

//abort service on unload
function unload() {
        if (abortExecutor != null) {
            abortExecutor.abort();
        }
    }

Helpful/Similar links for the background:

browser-waits-for-ajax-call-to-complete-even-after-abort-has-been-called-jquery
aborting-an-asp-net-web-service-asynchronous-call
canceling-ajax-web-service-call

Anybody faced this before? Its driving me nuts! Any help will be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绾颜 2024-08-05 11:05:43

您的一个链接中的答案对我来说听起来像是问题:
浏览器等待 ajax即使在调用 abort 后也要完成调用 (jQuery)

您的服务是否需要会话状态?

您可以通过将 IE 配置为允许对同一域发出 2 个以上的请求来证明问题是否是 IE 本身不会发出请求。 如果它被阻止是因为中止的请求以某种方式耗尽了这些连接之一,那么增加它应该会产生不同的结果。 如果仍然有问题,则一定是服务器正在等待响应。

为 2 个以上的请求配置 IE:
http://support.microsoft.com/kb/282402

引用SO问题之一你链接:

事实证明我完全错误地认为这是浏览器问题 - 问题出在服务器上。 ASP.NET 序列化需要会话状态的同一会话的请求,因此在本例中,直到这些 ajax 发起的请求完成后,下一页才会开始在服务器上处理。

不幸的是,在这种情况下,响应 ajax 调用的 http 处理程序中需要会话状态。 但只读访问已经足够好了,因此通过用 IReadOnlySessionState 而不是 IRequiresSessionState 标记处理程序,会话锁就不会被持有,问题就得到了解决。

The answer in one of your links sounds like the problem to me:
Browser waits for ajax call to complete even after abort has been called (jQuery)

Does your service require session state?

You could prove whether the problem is that IE itself won't issue the request by configuring IE to allow for more than 2 requests to the same domain. If it's being blocked because the aborted request is somehow eating up one of those connections, then increasing it should yield different results. If it still has the problem, it must be that the server is waiting to respond.

Configure IE for more than 2 requests:
http://support.microsoft.com/kb/282402

Quote from one of the SO questions you linked:

It turns out I was completely wrong about this being a browser issue - the problem was on the server. ASP.NET serializes requests of the same session that require session state, so in this case, the next page didn't begin processing on the server until those ajax-initiated requests completed.

Unfortunately, in this case, session state is required in the http handler that responded to the ajax calls. But read-only access is good enough, so by marking the handler with IReadOnlySessionState instead of IRequiresSessionState, session locks are not held and the problem is fixed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文