我想使用的自动启动设施,以确保我的应用程序缓存总是被填充,并准备去,如ScottGu's blog描述。我在配置它时遇到了一些问题。自动启动ASP.NET应用程序 - 配置错误
该项目有冰激凌,我使用的是Windows 7的工作头衔,IIS 7.5,ASP.NET 4.5。
在IIS中,我创建了一个新的应用程序池IceCreamPool
,并且我修改了applicationHost.config
,详见博客文章。
首先:我加入了startMode
到AlwaysRunning
上的应用程序池:
<applicationPools>
...
<add name="IceCreamPool" autoStart="true" managedRuntimeVersion="v4.0" startMode="AlwaysRunning" />
...
</applicationPools>
接下来,我添加了serviceAutoStartEnabled
和serviceAutoStartProvider
到应用程序:
<application path="/IceCreamCMS" applicationPool="IceCreamPool">
<virtualDirectory path="/" physicalPath="C:\Projects\IceCreamCMS\IceCreamCMS" serviceAutoStartEnabled="true" serviceAutoStartProvider="PreWarmMyCache" />
</application>
然后我说服务汽车开始提供商,只是<sites>
元素之后:
<sites>
...
</sites>
<serviceAutoStartProviders>
<add name="PreWarmMyCache" type="IceCreamCMS.PreWarmCache, IceCreamCMS" />
</serviceAutoStartProviders>
在应用程序中,IceCreamCMS
,我创建了一个叫做PreWarmCache
类如下:
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...");
}
}
我然后重建应用程序,但没有电子邮件是即将到来的。
我执行的iisreset
,看看我收到一封电子邮件,然后,但iisreset
给了我一个错误:
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.
有applicationHost.config
绝对是良好的,我还没有做出一个基本的错字,我跑它通过一个XML验证器来确认。所以,下一个显而易见的地方就是它在错误中声明的配置文件,但它不存在,所以我猜测它是因为它在\ temp \中,它不会长时间粘在我看来在。
我知道有一个问题,无论是我的C#位,或者我是如何配置的serviceAutoStartProviders,因为如果我删除serviceAutoStartProviders
部分,并从<application>
元素中删除的设置,在应用程序池只留下startMode="AlwaysRunning"
,然后我没有问题。
那么 - 任何想法?你如何将你的班级映射到serviceAutoStartProvider
?我试过让我的类没有名字空间,名称空间是应用程序的名称(IceCreamCMS
)和更长的名称空间;一切都无济于事。
如果任何人实际上得到了这个工作,你能分享你的配置和C#代码?最初的博客文章令人沮丧地没有给出最后的工作示例!