我怎么能放弃在ASP.NET MVC的行动行动、我怎么能、NET、ASP

2023-09-10 16:30:30 作者:我拿青春乱了浮生

我要停止通过在服务器端的 jQuery.ajax 方法中调用的操作。 我可以使用 $。ajax.abort()方法在客户端而不是在服务器端停止Ajax请求。

I want to stop the actions that are called by the jQuery.ajax method on the server side. I can stop the Ajax request using $.ajax.abort() method on the client side but not on the server side.

更新:

我用异步操作而不是同步的动作,但我没有得到我想要的!正如你所知道的服务器无法处理,同时这将导致每个请求必须等到pvious一个结束,即使previous请求由$ .Ajax.Abort取消了$ P $(多个请求)的方法。 我知道,如果我用[SessionState会(System.Web.SessionState.SessionStateBehavior.ReadOnly)属性几乎是我想要的,但它并不能满足我。

I used async action instead of sync action, but I didn't get what I want! As you know server can't process more than one request at the same time that's causes each request have to wait till the previous one is finished even if previous request is canceled by $.Ajax.Abort() method. I know if I use [SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)] attribute it almost what I want but it doesn’t satisfy me.

首先我要放弃在服务器端的处理方法,通过用户。就是这样:)

Above all I want to abort processing method on server side by user. That's it :)

推荐答案

您可能想看看使用下列类型的控制器的在ASP.NET MVC 使用异步控制器

You may want to look at using the following type of controller Using an Asynchronous Controller in ASP.NET MVC

和也看看这篇文章可以帮助你和取消异步Web服务调用,对不起,我不能给任何code例子这个时候。

and also see if this article helps you out as well Cancel async web service calls, sorry I couldn't give any code examples this time.

我创建了一个例子作为概念证明,说明你可以取消服务器端的请求。 我github上异步取消例如

I've created an example as a proof of concept to show that you can cancel server side requests. My github async cancel example

如果你调用其他网站通过你的code,你有两个选择,这取决于你的目标框架,你想用哪一种方法。我包括在这里引用您的评论:

If you're calling other sites through your code you have two options, depending on your target framework and which method you want to use. I'm including the references here for your review:

WebRequest.BeginGetResponse 在使用.NET 4.0中 HttpClient的用于在.net 4.5本,类有一个方法来取消所有未决的请求。

WebRequest.BeginGetResponse for use in .Net 4.0 HttpClient for use in .Net 4.5, this class has a method to cancel all pending requests.

希望这给你足够的信息来达到自己的目标。

Hope this gives you enough information to reach your goal.