简体   繁体   English

ASP.NET应用程序是否可以向启动Application_Start事件的用户显示等待屏幕?

[英]Is there a way for an ASP.NET app to show a wait screen to the user that kicks off the Application_Start event?

Greetings folks, 问候大家,

The ASP.NET application I'm maintaining has a fairly long start up procedure. 我要维护的ASP.NET应用程序的启动过程相当长。 A number of data files are updated, etc. I've been asked if there is a way for the application to return a wait screen (static if necessary) while Application_Start is running? 许多数据文件已更新,等等。有人问我,是否有一种方法可以在Application_Start运行时让应用程序返回等待屏幕(必要时为静态)?

No, there's not. 不,没有。 ASP.Net needs to initialize the pipeline and everything else just to get to the point of being able to actually handle the request. ASP.Net需要初始化管道以及其他所有内容,以便能够实际处理请求。

Prior to that point, .Net has no idea what the request is, nor what the potential outcome might be. 在此之前,.Net不知道请求是什么,也不知道可能的结果是什么。 For example, it might be a web service call which has no response. 例如,它可能是一个没有响应的Web服务调用。 Or the request might cause a document to download at which point you don't want to have any data sent to the client yet. 否则,该请求可能会导致文档下载,此时您还不想将任何数据发送到客户端。

Instead, I'd look into two things. 相反,我将研究两件事。 First, how to reduce the app_start time; 首先,如何减少app_start时间; and, second, why would an application_start event be kicked off more than once in a blue moon. 其次,为什么会在一个蓝月亮中多次启动application_start事件。

从理论上讲,您可以为等待屏幕提供一个基本的HTML页面,该页面(使用javascript)在iframe中加载您的一个asp.net页面,并在加载时重定向到主应用着陆页,但这是可怕的黑客行为,我想价值,我自己。

I don't think you can accoplish what you want very easily, but I would recommend precompilation. 我认为您无法轻松实现所需的功能,但是我建议您进行预编译。 Pre-compiling your code saves a lot of time when deploying and getting that app started up. 预编译代码可在部署和启动该应用程序时节省大量时间。

How to: Precompile ASP.NET Web Site Projects 如何:预编译ASP.NET网站项目

From Microsoft: Precompiling an ASP.NET Web site project provides faster initial response time for users since pages do not have to be compiled the first time they are requested. 来自Microsoft:预编译ASP.NET网站项目为用户提供了更快的初始响应时间,因为不必在第一次请求页面时就对其进行编译。 This is particularly useful for large Web sites that are updated frequently. 这对于经常更新的大型网站特别有用。

Here's a possible solution: 这是一个可能的解决方案:

You could, in your App Start, kick off a worker thread that actually goes off and loads the data and processes everything that you need to do. 您可以在App Start中启动一个工作线程,该工作线程实际上会关闭并加载数据并处理您需要做的所有事情。 You'd set an Application() variable to say that the thread is running and that it hasn't completed yet. 您将设置一个Application()变量,以表明该线程正在运行并且尚未完成。

Then, whenever you get a request, check that Application() variable and display your "waiting" page (probably something that redirects itself periodically). 然后,每当您收到请求时,请检查Application()变量并显示“等待”页面(可能是定期重定向其自身的页面)。

Finally, when the worker thread finishes, it can set the Application() variable to indicate that the thread is complete. 最后,当工作线程完成时,可以设置Application()变量以指示线程已完成。

Something (very roughly) like this> In AppStart: 在AppStart中(大致)这样:

Application("StartupProcessingComplete") = False  
t = New Threading.Thread(AddressOf WorkerFunction)  
t.Start()  

In the WorkerFunction: 在WorkerFunction中:

<Do the work>
Application("StartupProcessingComplete") = True

In your Page Init, check the variable 在您的Page Init中,检查变量

If Not Application("StartupProcessingComplete") Then
    <Redirect to "Wait" page>
Endif

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

相关问题 是否可以在asp.net Web表单中添加除Application_start事件以外的路由 - Is it possible to add routes other that Application_start Event in asp.net web forms asp.net application_start事件中的问题……它非常非常慢……可能是什么原因? - problem in asp.net application_start event…its very very slow…what could be the reason? ASP.net Application_Start捕获计时器中的异常 - ASP.net Application_Start catch exception in timer 访问在Application_Start ASP.NET MVC 3中创建的变量 - Accessing Variables Created In Application_Start ASP.NET MVC 3 ASP.NET MVC3调试Application_Start - ASP.NET MVC3 Debugging Application_Start asp.net:调试缓慢-始终触发application_start - asp.net: slow debugging - always fire application_start 如果本地运行ASP.NET应用程序,则在Global.Asax中查找-Application_Start - Find out in Global.Asax - Application_Start if ASP.NET application running locally 在asp.net中托管套接字服务 - 与application_start和application_end有关 - Hosting a socket service in asp.net - issues with application_start & application_end 当无法访问Application_Start时如何向第三方asp.net应用程序添加路由 - How to add routes to a 3rd party asp.net application, when no access to Application_Start is available 在调用Application_Start()之后,Asp.Net MVC应用程序属性始终为null - Asp.Net MVC application Property is always null after Application_Start() is called
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM