简体   繁体   English

从控制台应用程序自动重启IIS网站

[英]Auto restart IIS Website from console application

We have an ASP.Net application used by many customers installed on their own servers. 我们有一个ASP.Net应用程序,供许多安装在自己服务器上的客户使用。 Because it is installed on their end with each having different databases and URL bindings etc I created a console application a while ago that gets a zip file and extracts it to c:\\inetpub location to append the latest application changes. 因为它安装在它们的末端,并且每个数据库都有不同的数据库和URL绑定等,所以我不久前创建了一个控制台应用程序,该应用程序获取一个zip文件并将其解压缩到c:\\ inetpub位置以附加最新的应用程序更改。 This console app is added to scheduled tasks to create an automated update. 此控制台应用程序已添加到计划的任务中,以创建自动更新。

Obviously when anyone accesses the site for the first time after it does this they have to wait a little longer whilst the site rebuilds. 显然,当有人这样做后第一次访问该站点时,他们必须等待更长的时间才能重建站点。 I changed the console application to include a Process.Start(urlofapp) so that it should hopefully do this as part of the update so the next morning that first user doesn't have to wait for the rebuild. 我更改了控制台应用程序,使其包含Process.Start(urlofapp),以便它有望作为更新的一部分进行操作,以便第二天早晨,第一个用户不必等待重建。

I have tested it ok running myself but not yet released as my concern is that this url process is kept open. 我已经在自己运行时进行了测试,但还没有发布,因为我担心此url进程保持打开状态。 Can anyone enlighten me as to whether this would be the case as I don't want this to happen or can give me any ideas as to how to rebuild the site manually as part of the console app. 任何人都可以启发我是否会发生这种情况,因为我不希望这种情况发生,或者可以给我任何有关如何在控制台应用程序中手动重建站点的想法。

IIS has had an auto-start apps feature for quite some time. IIS具有自动启动应用程序功能已有一段时间了。 You just have to enable it. 您只需要启用它。 You can find more info from the Gu , and the IIS site . 您可以从GuIIS站点中找到更多信息。

Safer instead to use a start page which loads everything on the server in the background. 使用起始页在后台将所有内容加载到服务器上更为安全。 If you do this logic in an async method which in turn is called from an MVC controller for example then this can potentially run whilst the main page has finished. 如果在异步方法中执行此逻辑(例如,又从MVC控制器调用该方法),则该逻辑有可能在主页完成后运行。 Alternatively use a threaded Task and show a start page that is only returned whilst setup is taking place. 或者,使用带螺纹的任务并显示一个起始页,该起始页仅在进行设置时返回。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM