N
N
Nikolai2018-03-12 15:07:36
IIS
Nikolai, 2018-03-12 15:07:36

How to make a site work on iis without requests to the site?

Is there a way to make the site work even if there are no requests to it? The fact is that the site has code that performs scheduled work using quartz. But if there are no requests to the site, then the code is not executed.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
cicatrix, 2018-03-12
@cicatrix

Usually, scheduled tasks are hung up on CRON (or an analogue), that is, this is a task independent of the web server.
If the site is on its own server or VDS - there is nothing easier to hang up the task to be performed periodically.
If on a hosting - contact them, any hoster probably has a similar service (or, in any case, you can agree) ...
Well, if Monsieur is a pervert, then you can organize the execution of a web request on any other machine with a given frequency, but this , I repeat, a perversion.
A web server serves one purpose - SUDDENLY - to serve web requests. Everything else he should not do (and is not intended for this).
UPDATE: Didn't read it - quartz should normally be hosted on a machine as a windows service.

B
basrach, 2018-03-13
@basrach

1. Find the IIS settings file: %WINDIR%\System32\inetsrv\config\applicationHost.config
2. Find the applicationPools section in this file, find the required appPool there, add/replace attributes with autoStart="true" startMode="AlwaysRunning", should be like this:

<applicationPools>
  <add name="DefaultAppPool" autoStart="true" startMode="AlwaysRunning" managedRuntimeVersion="v4.0">

3. Find the sites section, in it the desired site, and there the desired application and add two attributes to the application tag there: serviceAutoStartEnabled="true" serviceAutoStartProvider="ApplicationPreload"
<sites>
    <site name="Default Web Site" id="1" serverAutoStart="true">
        <application path="/" serviceAutoStartEnabled="true" serviceAutoStartProvider="ApplicationPreload"

4. Below, right after the sites section or before the closing system.applicationHost tag, add:
<serviceAutoStartProviders>
    <add name="ApplicationPreload" type="MyNamespace.ApplicationPreload, MyAssembly" />
</serviceAutoStartProviders>

Note! The value of name must match the value of serviceAutoStartProvider .
The type value must be the full name of the loader class (namespace, assembly) that will launch quartz when the site starts.
5. Implement the loader class itself:
public class ApplicationPreload : System.Web.Hosting.IProcessHostPreloadClient
{
    public void Preload(string[] parameters)
    {
        // Qurtz.Net.Start() // или как там хз
    }
}

At the same time, it must be remembered that the pool can still be "beaten" by IIS, for example, if the memory limit is exhausted. An unhandled exception in your code can also stop it. But after stopping it should start immediately. Those. you can't expect some code to run 24/7. It will interrupt, but start immediately.
Also, it is better to repeat the qurtz startup code (the one in the Preload(string[])) method in the Application_Start method in Global.asax for reliability.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question