重新编译asp.net网站时如何重新启动IIS站点
添加到 Asp.net 项目的构建/编译脚本中以启动 IIS 在 DLL 重建上重新启动网站而不是对网站的第一个请求的最佳方法是什么?
当前进程
- 编译项目
- 等待
- 点击 APSX 页面
- IIS 开始重新加载
- 等待
- 页面加载
理想的过程:
- 编译项目并加载重新加载 IIS
- 等待命中
- APSX 页面
- 页面加载
我想到的第一种方法是添加一个请求,仅命中“构建后事件”中的一个页面。只是想知道最佳实践。这类似于“开始”,它在构建时立即打开一个页面。
更新: 我之所以要这样做,只是为了提高效率。我会将编译时间和重新启动时间封装到一批中,以节省
- VS下面第4步的时间: ctrl+shift+b
- 等待视觉提示“构建成功”。
- 浏览器:F5。
- 等待 IIS 重新加载。 (以及在SO中未回答的问题中点击kbd>F5)
- 测试页面
What is the best way to add into the build/compile script of an Asp.net project to initiate a IIS to restart the website on DLL rebuild instead of the first request to the site.
Current Process
- Compile Project
- Wait
- Hit APSX Page
- IIS starts reload
- Wait
- Page loads
Ideal process:
- Compile Project & Reload IIS
- Wait
- Hit APSX Page
- Page loads
The first way I though of was add a request to just hit one of the pages in the "Post-Build events". Just wondering best practices. This would be similar to "Start" which opens a page immediately on build.
Update:
The reason I would like to accomplish this is for just for efficiency. I would the to encapsulate the compile time and the restart time into one batch to save on time on step 4 below
- VS: ctrl+shift+b
- Wait for visual que "Build succeeded".
- Broswer: F5.
- Wait for IIS reload. (as well as Hit kbd>F5 in unanswered questions in SO)
- Test page
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将“iisreset /stop”添加到预构建事件中,并在构建后事件结束时添加“iisreset /restart”。
正如大卫提到的,您应该尝试找出根本问题所在。如果您在首次加载网站时遇到性能问题,这是很正常的。初始编译通常需要一些时间。重置 IIS 只会让它花费更长的时间。如果还有其他问题,请在此处发布您这样做的原因,我们可以看看是否可以帮助您。
Add ‘iisreset /stop’ into the Pre-Build event and ‘iisreset /restart’ at the end of the Post-Build event.
As David mentioned, you should try to find out what the underlying issue is here. If you are experiencing performance issues when first loading a website, this is quite normal. The initial compilation often takes some time to occur. Resetting IIS is only going to make it take longer. If there is another issue, please post your reason for doing this here, and we can see if we can help you.
一种简单的方法是编写 shell vb 脚本或 PowerShell 脚本来使用 XmlHttpRequest 从站点请求页面,并将其作为构建后任务包含在内。
您觉得有必要这样做有什么特别的原因吗?如果您在第一次 JIT 时遇到性能问题,那么您可能需要考虑将应用程序分解为较小的项目/DLL(假设大小是问题),或者开始查看应用程序启动时出现的瓶颈。
还有一个问题:为什么IIS会重置?这不会导致 DLL 重新编译,直到第一个页面请求为止。与经典 ASP 不同,无需重新启动 IIS 即可允许 DLL 更改/生效。
A naive way would be to write a shell vb script or PowerShell script to use XmlHttpRequest to request a page from the site, and include that as a post-build task.
Is there any particular reason you feel the need to do this? If you're experiencing performance issues at the first JIT then you may need to consider breaking up your application into smaller projects/DLLs (assuming that size is the issue), or start looking at bottlenecks that occur when your app starts.
Another question: why the IIS reset? That won't cause the DLL to be recompiled until the first page request. Unlike classic ASP, it isn't necessary to restart IIS for DLL changes to be allowed/take effect.
您希望从进程中删除的“等待”很可能是 aspx 标记页面编译。当你在 VS 中构建时,默认情况下它会编译你的所有代码,但不会编译你的标记 aspx 页面。您可以通过添加 Web 部署项目到您的解决方案,它允许您预编译标记页面。这样,部署后的初始加载时间不应与任何其他加载时间有太大差异。
The "wait" you are hoping to remove from the process is most likely the aspx markup pages compiling. When you build in VS by default it will compile all your code, but it will not compile your markup aspx pages. You can get round this by adding a Web Deployment Project to your solution, which allows you to precompile the markup pages. This way the initial load time after deployment should not be very much different to any other load time.