[英]How manually create first request for asp.net mvc on iis7.5 when every time restart or release the website?
你们都知道:在IIS7.5上 ,第一个请求非常慢 。 因此,我认为也许我可以在网站每次启动,重新启动,周期时间结束后手动创建请求 。
我进行了很多搜索,然后发现了自动启动功能: http : //www.schwammysays.net/auto-starting-websites-on-iis-7-5/
添加此代码后,我在Global.asax的 Application_Start()中手动创建一个请求
protected void Application_Start()
{
'' original logic here ''
System.Threading.Tasks.Task.Factory.StartNew(new Action(() =>
{
try
{
// send request after 100 second
System.Threading.Thread.Sleep(1000 * 100 * 1);
WebClient webClient = new WebClient();
using (Stream stream = webClient.OpenRead(ConfigurationManager.AppSettings["InitialPath"]))
{
if (stream.CanRead)
{
log.Debug("warm success");
}
else
{
log.Debug("can't read");
}
}
}
catch (Exception ex)
{
log.Error(ex);
}
}));
}
但问题是:1.仅在IIS7.5循环时间结束时才触发。 重新启动网站,启动或释放网站时不会触发(甚至更改web.config)。 2.有些网站仍然没有被解雇,我听不懂。
因此,我正在搜索网站启动,更改,重新启动,IIS循环时间结束时,还有其他方法可以触发Application_Start()或创建请求吗? 我的服务器是:Windows Server 2008 R2
您要查找的搜索词是“应用程序预热”。
您可以将应用程序初始化模块用于IIS 7.5 。 设置说明可在此处和此处找到。 请注意,您需要对applicationHost.config
进行一些编辑,并且需要专门针对.NET Framework版本进行设置。
然后,您可以在web.config
拥有类似的内容
<applicationInitialization
doAppInitAfterRestart="true" >
<add initializationPage="/" />
</applicationInitialization>
每次您的应用程序自动启动时,这会将请求发送到您的应用程序的根目录( initializationPage="/"
)。
在这里找到答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.