tags:

views:

33

answers:

2

What details can I get of the process hosting my ASP.NET code (i.e. Cassini, IIS etc)?

I know of System.Environment but its not overly informative for web apps.

Is there anything else available?

Thanks

+1  A: 

You can get some more info from HttpRuntime, but not everything.
http://msdn.microsoft.com/en-us/library/system.web.httpruntime_members.aspx

StephaneT
+3  A: 

If you only are interested in what kind of environment that you are running in, you can check

AppDomain.Current.FriendlyName 

or

System.Diagnostics.Process.GetCurrentProcess().MainModule.ModuleName

We have a test like this in a project:

AppDomain appDomain = AppDomain.CurrentDomain;
if (appDomain.FriendlyName.ToUpper().StartsWith("/LM/W3SVC/") || // IIS
  appDomain.FriendlyName.ToLower().EndsWith(".test.dll") ||       // Support for unit test as long as it ends with .test.dll.
 (System.Diagnostics.Process.GetCurrentProcess().MainModule != null) && System.Diagnostics.Process.GetCurrentProcess().MainModule.ModuleName.Equals("WebDev.WebServer.EXE", StringComparison.CurrentCultureIgnoreCase))     // Support for Cassini.
{
    ...
}

It is not pretty, but it works.

Andreas Paulsson
Thanks guys, both useful answers. Accepted @StephaneT's as it has the data I was looking for (perhaps i worded my question badly) although very useful to know about these two suggestions for future reference!
Andrew Bullock