Tutorial :How can I detect if my .NET assembly is running from web site or from a desktop machine?


I just want to write code inside my assembly to detect whether it is running on a "desktop machine", or inside the context of an ASP.NET application. This is crucial guys, (licensing purposes), and I don't want to get fired because I did a mistake.

So, please, be direct and if you please give me some code snippet.

EDIT: I depend on your answers

EDIT v 2.0: What about using in the assembly:

[assembly: "AspNetHostingPermission (SecurityAction.RequestRefuge, Unrestricted=true)]"  

to prevent the execution on the web?


This might be helpful:

How determine if application is web application


Check whether the HttpContext.Current is null and then report it's not running as a web app, e.g.:

if (HttpContext.Current == null) {       // Report that it is not running as web app.  }  

You will have to make a reference to the System.Web in your references and you using statement.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »