简体   繁体   中英

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. The view is returning some data which is hidden to most website users (it is mostly used for 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). 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.

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?

Unfortunately, there is nothing (out of the box) in MVC that will allow you to do such a thing.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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