如何限制/阻止 .net 代码在互联网上执行?
我开发了一系列 .NET 类库,但我不希望它们从网站运行。也就是说,用户只能通过 Windows 桌面应用程序使用/调用我的库。例如,我不希望用户能够在网站上的 ASP.NET Web 应用程序中使用这些库。有办法实现这一点吗?
I develop a series of .NET class libraries and I don't want them to run from a web site. That is, users could only use/call my libraries through windows desktop applications. For example I don't want the users to be able to use these libraries in an ASP.NET web application, on a web site. Is there a way to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以通过检查
HttpRuntime.AppDomainAppVirtualPath
是否不null
并引发异常来阻止代码在服务器端 ASP.Net AppDomain 中运行。但是,这不会阻止某人在与 ASP.Net 不同的 AppDomain 中运行您的应用程序,也肯定不会阻止某人将应用程序作为服务运行并使用 WCF 或命名管道将其公开给 ASP.Net。
你为什么要尝试这样做?
编辑:要回答您的评论,这也是不可能做到完美的。
您可以检查 HOST 标头,有人可以使用
SimpleWorkerRequest
来击败它。此外,任何东西都可以通过编辑程序集来击败。 (没有混淆器是完美的)
You can prevent your code from running in a server-side ASP.Net AppDomain by checking whether
HttpRuntime.AppDomainAppVirtualPath
is notnull
and throwing an exception.However, that won't stop someone from running your app in a separate AppDomain from ASP.Net, and it certainly won't stop someone from runnng the app as a service and exposing it to ASP.Net using WCF or named pipes.
Why are you trying to do this?
EDIT: To answer your comment, that's also impossible to do perfectly.
You could check the HOST header, and someone could defeat it using
SimpleWorkerRequest
.In addition, anything can be beaten by editing the assembly. (No obfuscator is perfect)
不会。即使您要阻止您的库在 IIS 下运行,其他人仍然可以使用您的库运行桌面应用程序,并从 IIS 与其进行通信。
No. Even if you were to stop your library from running under IIS, somebody could still run a desktop app with your library, and communicate with it from IIS.
不,不是真的。
但是,根据您的应用程序是什么,您可能能够削弱其在线使用的应用程序。如果您使用命名互斥体,则可以确保任一时间仅启动 1 个操作。与启动桌面应用程序的 1 个实例类似,您可以确保对 DoWork() 等的所有调用都是连续的。
这意味着使用网络,他们无法重复拨打电话。但这确实取决于您设想它在桌面应用程序中的使用方式。
No, not really.
However, depending on what your application is you may be able to cripple it's application for use online. If you use named mutexes you can ensure only 1 operation ever starts at any one time. Similar to starting 1 instance of a desktop application, you ensure that all calls to DoWork() for example are sequential.
This means that using the web, they couldn't make repeated calls. But it does depend on how you envisage it's use in a desktop app.
正如其他解决方案不太安全一样,但您可以使用 Application.MessageLoop 通常适用于 WinForms 应用程序,但不适用于 Web 应用程序。
Just as the other solutions not very safe, but you could check if a message loop is running using Application.MessageLoop which should typically be true for WinForms applications but not for web applications.