views:

100

answers:

2

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?

+3  A: 

This might be helpful:

http://stackoverflow.com/questions/3179716/how-determine-if-application-is-web-application

afolkesson
You're probably right. I didn't search for it and I only saw what was listed after I entered the question. So, I give you the credits.I'll check it. Thank you.
Darryl
Now that I am thinking: if someone create an executable (console) and call it would the same code still be valid? I don't have experience with ASP.NET and don't know the tricks.
Darryl
+2  A: 

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.

Turnkey
You have a point. I merged your proposal with the above (afolkesson) in a statement.
Darryl
Yes, that will help you
ileon