How to get the latest time for an ASP.NET application?

How to get the last time the current ASP.NET application was launched?

+4
source share
3 answers

I think create a static class with a static constructor that assigns the DateTime.Now property.

+3
source

You can set the static field in DateTime.Now in Application_Start in Global.asax.

+5
source

If you want to discard the extra variable, I think this will give you the last time the IIS workflow (aka application pool) was restarted:

 System.Diagnostics.Process.GetCurrentProcess().StartTime 

I use it to set caching because the page is based on the content that I dynamically generate when the application starts:

 Response.Cache.SetLastModified(System.Diagnostics.Process.GetCurrentProcess().StartTime); 

You can stop / start individual websites within the application / workflow pool, but I exit this post that it does not recreate the static objects of the application, so I understand that the date associated with the workflow is probably the most useful date here.

Remember also that the static application variable created when the application was launched actually actually gives you the time when the application was first visited. Perhaps the workflow was started much earlier, and this takes into account phrases such as “warm up IIS applications” and “autostart IIS applications”, as well as another discussion of when static fields are initialized as a whole. What you choose may depend on whether you are interested in the last time the workflow was processed or if you are interested in how long the other static members were calculated.

+4
source

Source: https://habr.com/ru/post/1339676/


All Articles