简体   繁体   中英

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?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM