简体   繁体   English

MVC3操作在超时后返回EmptyResult吗?

[英]MVC3 action return EmptyResult after timeout?

I'm currently calling the Facebook graph API from one of my actions which returns a partial view with a model. 我目前正在从我的操作之一调用Facebook图形API,该操作返回模型的部分视图。 The view is returning some data which is hidden to most website users (it is mostly used for SEO). 该视图返回的数据对大多数网站用户都是隐藏的(大多数用于SEO)。

We have some software which monitors the time taken to call external APIs from our site and every now and then we're noticing that the Facebook Graph API is taking a long time to respond, resulting in our users waiting forever for a page to load (even when they likely won't even see the content we're trying to pull back from the API). 我们有一些软件可以监控从我们网站调用外部API所花费的时间,并且不时发现,Facebook Graph API需要花费很长时间进行响应,从而导致我们的用户永远等待页面加载(即使他们可能甚至看不到我们正在尝试从API撤回的内容)。 Seeing as this call is not business-critcial, I need a way in which to get the aforementioned action to simply return an EmptyResult() and just not bother waiting for a response from the Facebook API after a given timeout period. 鉴于此调用不是关键业务,因此我需要一种方法来获取上述操作,以简单地返回EmptyResult()而不必在给定的超时时间后费心等待Facebook API的响应。

Does anyone know of a way in which I can set a timeout on the action, and then return an EmptyResult if the timeout is exceeded? 有人知道我可以在操作上设置超时,然后在超时后返回EmptyResult的方法吗?

Unfortunately, there is nothing (out of the box) in MVC that will allow you to do such a thing. 不幸的是,MVC中没有(开箱即用的)东西可以让您做这样的事情。

But, if you're using MVC2 or 3 you can use asynchronous action methods and hand off your work to a CLR thread and simultaneously start a Timer that will signal to ASP.NET ( using AsyncManager.Sync ) to return an EmptyResult (if the CLR thread work has not completed). 但是,如果您使用的是MVC2或3,则可以使用异步操作方法并将工作移交给CLR线程,同时启动一个Timer ,该信号将向ASP.NET发出信号( 使用AsyncManager.Sync )以返回EmptyResult(如果CLR线程工作尚未完成)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM