0

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.

RayLoveless
  • 19,880
  • 21
  • 76
  • 94

2 Answers2

1

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.

Community
  • 1
  • 1
Robert Koritnik
  • 103,639
  • 52
  • 277
  • 404
  • So you're saying that things are pretty much fine the way I have it set up and if I wasn't using mvc and had a regular .aspx page, without any code behind peices in it, then that might be a different story. Does this sound correct? – RayLoveless Nov 23 '10 at 18:30
  • @Ray L: Yes they're fine as long as you don't have other assemblies that are being used by your application. If you weren't having an MVC application but had a **web site** application type instead, then it would be different and your code wouldn't work as expected. It it was a **web application** it would still work just as well. – Robert Koritnik Nov 23 '10 at 18:35
0

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"?

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123