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.
我只想在程序集中编写代码来检测它是在“桌面计算机”上运行,还是在ASP.NET应用程序的上下文中运行。这是至关重要的人,(许可目的),我不想被解雇,因为我犯了一个错误。
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:
编辑v 2.0:如何在程序集中使用:
[assembly: "AspNetHostingPermission (SecurityAction.RequestRefuge, Unrestricted=true)]"
to prevent the execution on the web?
防止在网上执行?
2 个解决方案
#1
4
This might be helpful:
这可能会有所帮助:
How determine if application is web application
如何确定应用程序是否是Web应用程序
#2
3
Check whether the HttpContext.Current is null and then report it's not running as a web app, e.g.:
检查HttpContext.Current是否为null,然后报告它没有作为Web应用程序运行,例如:
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.
您必须在引用中引用System.Web并使用statement。
#1
4
This might be helpful:
这可能会有所帮助:
How determine if application is web application
如何确定应用程序是否是Web应用程序
#2
3
Check whether the HttpContext.Current is null and then report it's not running as a web app, e.g.:
检查HttpContext.Current是否为null,然后报告它没有作为Web应用程序运行,例如:
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.
您必须在引用中引用System.Web并使用statement。