Displaying a stub page when starting an ASP.NET application

Is it possible to display a specific page while the ASP.NET application is still in the initialization process?

We have a huge ASP.NET application that takes about 30 seconds to complete the Application_Start() handler after each redeployment or restart of AppDomain. Displaying a good reloading page "temporarily unavailable" during this time will greatly improve the experience for first users.

I tried to extract the initializer code to another thread, but it has many dependencies: HttpContext , Server and several other classes are not available from derived streams. The code becomes interdependent and incompatible, so I'm looking for the best solution. Maybe some configuration or extension of IIS?

+7
c # asp.net-mvc iis
source share
3 answers

Well, since IIS 7.5 you can use Application Initialization ( http://www.iis.net/downloads/microsoft/application-initialization ) for this, which will allow you to either show a β€œ-Screen splash” or simply pre-launch Application-Pools.

Here is an explanation for IIS8: http://www.iis.net/learn/get-started/whats-new-in-iis-8/iis-80-application-initialization It will work similar to IIS7.5, but there you should install the module in advance.

And here is the link taken from the comments: http://blogs.msdn.com/b/abhisk/archive/2013/08/16/configuring-application-initialization.aspx

+6
source share

You can load a static page or html page that are not executed when the system starts, and then through ajax poll / check something (value, etc.), which will be available only after the application starts, so you could have an animation or some download information on the page.

+1
source share

I think you are looking for something that is impossible. So you want to create an Application_Start that takes a lot of time, and you want your application to respond during that time. Application_Start is a synchronous event, meaning that no request will begin to process until it is completed. This is his job after all.

You need to somehow cancel your requirements. Here are some ideas.

New HTTP Level

As I said, you cannot run .NET code in your application until Application_Start completes. But you can run another, different application.

So, let me create another application that faces the customers. Reverse proxy or similar. I am sure there are reverse proxy implementations that allow you to do some scripting and solve the problem. On the other hand, I myself wrote a simple reverse proxy in C #. When he received the HTTP request, he created an HttpWebRequest and passed it to another URL. He supported GET and POST, he has been working in production for many years. If you are interested, I can share some information about this.

The only thing you need to decide is how your backend application interacts with the interface. It’s easy, you can use WCF, IPC, create a simple 0 byte file somewhere, nothing at all. When the Application_Start application starts, you can create this 0-byte file, and when it is complete, you will delete it.

Please note that after closing the application, many events occur, restarting and before starting Application_Start. Initializing IIS may take several seconds. Thus, instead of a 0-byte marker file that has only 2 states (exists / does not exist), you can open a simple WCF service with named pipes, for example. It can have 3 states: it does not respond at all (the application is stopped), it responds that the application is starting or responds that the application is running. This WCF service must be self-contained and run in the background because IIS will not respond explicitly.

HTML / JS magic

This is basically the same idea as above. This is simpler because you do not need to configure another application, but less flexible. You must create an HTML landing page for your application, and you must ensure that users are not bookmarking any other page. If you can do this, you're in luck. You can use the ideas from the solution above about how your application can communicate with the outside world during its launch. You cannot use simple web services hosted in IIS, but you can easily host your own WCF services (create your own ServiceHost, etc.). Of course, this self-service WCF service will not work on the same host: the port as your application. But it's pretty easy to expose the JSON service in WCF.

So, on the HTML landing page, you write JS AJAX code that requests your self-service JSON service. If there is no answer, you can inform the user that the application does not work at all. If the service says that it is running, you can inform the user about it. If the service says the application is running, you are redirecting your user.

This will not work if your users view your site after it is closed. See why you need a whole new layer.

Magic iis

For me, this is a somewhat uncertain territory. In integrated mode, .NET is an integral part of IIS, so it's hard for me to work with it. However, in classic mode, .NET starts as an ISAPI extension. Thus, it is theoretically possible to write a new ISAPI extension that runs before .NET. The bad news is that it should be written in C / C ++. But this is obvious because, as I said, you cannot run .NET code until Application_Start completes. But during this time, IIS has not died, so solve it at the IIS level. It can get ugly and I'm 99% sure that it is really possible.

Refactoring

Above are all workarounds. You really have to reorganize your code so that Application_Start ends quickly. It should not be a heavy function. There is already an infrastructure for preloading ASP.NET applications . If you tell us why you need HttpContext and Server in your initialization code, we are here to help you solve these problems.

+1
source share

All Articles