asp.net-mvc。如何判断 IIS 是否已准备好开始提供页面服务
我正在构建一个 asp.net MVC 2 应用程序,它有一个 ping 页面,可以让另一个系统知道该应用程序是否已启动并正在运行。我相信这也用于让负载均衡器了解活动节点。这是我的控制器操作中的内容。
public ActionResult PingApp()
{
// If we get here this node is alive. Echo "Ok".
return Content("OK");
}
我不相信它工作正常,因为当我启动或重新启动应用程序时,在应用程序真正准备好并“确定”之前需要设置许多其他任务。 (即,加载 dll、预编译 aspx 页面等...如果我理解正确的话)。我正在使用 IIS 7。有谁知道我如何检查 IIS 和我的应用程序是否真正“准备就绪”。
- 谢谢。
I'm building an asp.net MVC 2 application that has a ping page to let another system know if the application is up and running. I believe this is also used to keep the load balancer aware of active nodes. Here's what I have in my controller's action.
public ActionResult PingApp()
{
// If we get here this node is alive. Echo "Ok".
return Content("OK");
}
I do not believe it is working correctly because when I start or restart the application there a lot of other tasks that need to be set up before the app is truly ready and "OK". (ie, loading dll's, precompiling aspx pages etc.. if I understand things correctly). I'm using IIS 7. Does anyone know how I might check and see if IIS and My application is truly "ready".
- Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Asp.net MVC 是一个 Web 应用程序,而不是一个网站(此 stackoverflow 问题中的差异 ),它在每页的基础上进行预编译。 Asp.net MVC在运行时其DLL是完全JIT编译到平台上并运行的。
因此,如果您的页面是同一程序集的一部分,那么所有其他页面也应该运行。如果其他页面需要其他程序集的功能,则会按需加载它们。
加载所有程序集
如果您希望
PingApp
也加载这些程序集,那么您应该在其中调用一些虚拟功能,以便它们得到 JIT 编译、加载和执行。第一次调用
PingApp
将需要一些时间来实际 JIT 编译、加载您的 Web 应用程序并运行它。Asp.net MVC is a Web Application and not a Web Site (differences in this stackoverflow question), whitch pre-compiles on a per-page basis. Asp.net MVC when running its DLL is completely JIT-compiled to the platform and is running.
So if your page is part of the same assembly, all others should be running just as well. If other pages need functionality of other assemblies, then they're loaded on demand.
Load all assemblies
If you'd like your
PingApp
to load those as well, you should be calling some dummy functionality inside of them so they will get JIT-compiled, loaded and executed.The first call to your
PingApp
will take some time to actuall JIT compile and load your web application and run it.我想这取决于你所说的“真正准备好”是什么意思,但这个解决方案是有效的。
ASP.NET/IIS/.NET 故意不执行某些操作,直到绝对需要它们为止 - 例如加载尚未使用的类型或编译 ASPX 页面(其中包括此处的视图)。
如果您绝对想确保某些内容已“加载到内存中”,那么您只需要让您的操作通过以某种方式引用它们来加载它们。即使实例化类的默认实例也会导致该库被找到并加载。
但这真的有必要吗?当您真正想知道的是“服务是否正在运行”时,这是否会导致应用程序及其所有组件不必要的加载?
I suppose it depends on what you mean by 'truly ready', but that solution works.
ASP.NET/IIS/.NET purposefully do not do certain things until they are absolutely needed - like loading as-yet-unused types or compiling ASPX pages (which includes the Views here).
If you absolutely want to make sure certain things have been 'loaded in memory', then you will just need to have your Action cause them to be loaded, by referencing them somehow. Even instantiating a default instance of a class will cause that library to be found and loaded.
But is this really necessary? Will this cause unnecessary loading of the application and all the components of it, when all you really want to know is, "is the service running"?