powered by QualityHosting

Discover if launched from Web server

How do I know if my application has been launched from a Web server?

You just need to check if the codebase of your assembly starts with "http" or "https". However the Uri class of the .NET framework contains constants for the two values (UriSchemeHttp and UriSchemeHttps).

  using System.Reflection;

  ...

  string codeBase = Assembly.GetExecutingAssembly().CodeBase;

  if (codeBase.StartsWith(Uri.UriSchemeHttp) ||
      codeBase.StartsWith(Uri.UriSchemeHttps))
  {
    // app was launched via URL
 
}

[Comments]


 

 

   Copyright (C) 2003-2008 dotnet-online.com. All Rights reserved.

Contact Me | Legal