Reputation: 4642
I want to use the auto start facility to ensure my application cache is always populated and ready to go, as described in ScottGu's blog. I'm having some problems with configuring it.
The project has a working title of IceCream, I am using Windows 7, IIS 7.5, ASP.NET 4.5.
In IIS, I have created a new application pool, IceCreamPool
, and I have amended applicationHost.config
as detailed in the blog posting.
Firstly: I added the startMode
to AlwaysRunning
on the application pool:
<applicationPools>
...
<add name="IceCreamPool" autoStart="true" managedRuntimeVersion="v4.0" startMode="AlwaysRunning" />
...
</applicationPools>
Next, I added the serviceAutoStartEnabled
and the serviceAutoStartProvider
to the application:
<application path="/IceCreamCMS" applicationPool="IceCreamPool">
<virtualDirectory path="/" physicalPath="C:\Projects\IceCreamCMS\IceCreamCMS" serviceAutoStartEnabled="true" serviceAutoStartProvider="PreWarmMyCache" />
</application>
Then I added the service auto start provider, just after the <sites>
element:
<sites>
...
</sites>
<serviceAutoStartProviders>
<add name="PreWarmMyCache" type="IceCreamCMS.PreWarmCache, IceCreamCMS" />
</serviceAutoStartProviders>
Over in the application, IceCreamCMS
, I created the class called PreWarmCache
as follows:
using System.Net.Mail;
public class PreWarmCache : System.Web.Hosting.IProcessHostPreloadClient
{
public void Preload(string[] parameters)
{
// Perform initialisation and cache loading logic right here
SmtpClient s = new SmtpClient("webmail.example.com");
s.Send("[email protected]", "[email protected]", "Pre-warming the cache", "Hello there...");
}
}
I then rebuilt the application, but no emails were forthcoming.
I executed an iisreset
to see if I got an email then, but the iisreset
gave me an error:
The worker process for application pool 'IceCreamPool' encountered an error 'Configuration file is not well-formed XML ' trying to read configuration data from file '\?\C:\inetpub\temp\apppools\IceCreamPool\IceCreamPool.config', line number '3'. The data field contains the error code.
There applicationHost.config
is definitely well formed, I haven't made a basic typo, I ran it through an XML validator to confirm. So, the next obvious place to look would be the config file it states in the error, but it doesn't exist, so I'm guessing since it was in \temp\ it doesn't stick around long enough for me to look at.
I know there's a problem with either my C# bit, or how I've configured the serviceAutoStartProviders, since if I remove the serviceAutoStartProviders
section and remove the setting from the <application>
element, leaving just the startMode="AlwaysRunning"
on the application pool, then I get no problems.
So - any ideas? How do you map your class against the serviceAutoStartProvider
? I've tried having my class in no namespace, a namespace which is the name of the application (IceCreamCMS
) and a longer namespace; all to no avail.
If anyone's actually got this working, could you share your config and C# code? The original blog post frustratingly doesn't give a final working example!
Upvotes: 2
Views: 2812
Reputation: 4642
OK - I just tried out the exact same thing but deployed to a server running Windows Server 2008 and IIS7, and it worked perfectly.
So it must be something about IIS running on Windows 7 - but I'm happy that it's working on a server, so - no worries.
Upvotes: 1