简体   繁体   English

如果整个页面在MVC中花费30秒以上,则重定向到自定义视图

[英]Redirect to custom view in case overall page takes more than 30 seconds in MVC

I have a MVC view which is rendering multiple partial views and two action. 我有一个MVC视图,它正在渲染多个局部视图和两个动作。 In this scenario sometime we face page unresponsiveness issue. 在这种情况下,有时我们会遇到页面无响应问题。 So Can I implement any action filters type solution based on overall performance of View? 那么我可以基于View的整体性能实施任何动作筛选器类型的解决方案吗?

Basically I want to redirect to a custom page whenever this view takes more than 30 seconds. 基本上,只要此视图耗时超过30秒,我都希望重定向到自定义页面。

If UR using web.config file for setting idle timeout for each page 如果UR使用web.config文件为每个页面设置空闲超时

<system.web>
    <sessionState timeout="20" mode="InProc" />
.....

<authentication mode="Forms">
      <forms loginUrl="~/" slidingExpiration="true" timeout="20" />
    </authentication>

this above setting are know as server-side setting and redirecting page after 20min to perticular page. 将此设置称为服务器端设置,并在20分钟后将页面重定向到特定页面。

OR 要么

U Can use the client-side scripting for the same.Use following javascript code that you could run on every page load. U可以使用相同的客户端脚本。使用以下可在每次页面加载时运行的javascript代码。

SetTimeout(function()
{
window.location.href = "/"; // U can use @Url.Content("~/") inside the quotes to also or else give the page path  to the page U want to redirect 
}, 10 * 60 * 1000); // 10 mins * 60 sec/min * 1000 ms/sec. (set U R won timeout)

This code would redirect someone to the homepage after 10 minutes of idle on a page or take longer time to load the content. 此代码将使某人在页面上闲置10分钟后将某人重定向到首页,或者花费更长的时间来加载内容。

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

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