Sameers Portal

The purpose of these pages to share small piece of codes which helps developers. Usually it is harder to manage such pieces. Peoples usually make small projects to save their pieces, but this could be helpful as you can manage your codes here and also search. Top of all, these pieces are shared automatically among everyone. So you have chances to get your required piece of code immediately.

Share Code Now and make your own libraries


Category:

Techniques

Title:

Determine if ASP.NET Page is running in Cassini or IIS

Description:

Sometimes you'd really like to know whether your web application is running in IIS or Cassini (ASP.NET Developer Server or whatever it's called now). For example, I've heard there are certain scenarios that do not work under the latter and therefore must run under the former, so during automated test suites using Cassini you might want to avoid executing some blocks of code that you know will fail except under IIS. Regardless of *why* you might care, here is some code you can use to accomplish the task: System.Diagnostics.Process.GetCurrentProcess().MainModule.ModuleName Looking at this property you will see different values for IIS and for Cassini. For the VS web host, it will say something like "WebDev.WebServer.EXE". For IIS it will be something like "aspnet_wp.exe" or "w3wp.exe". In any event, you can use the differing values to determine which server environment your application is running in (including MONO for that matter, though I don't know what the string is for that), should you need to do so.

Posted On:

11/5/2007

Posted By:

Sameers (theAngrycodeR)

VB Version

C# Version