[英]How do I call a .Net control or class library from javascript on a web page in Internet Explorer?
I am working on an intranet app where it needs to collect system information from environment variable information from the client machine so it can be used in later processing by the server. 我正在开发一个Intranet应用程序,它需要从客户端计算机收集来自环境变量信息的系统信息,以便它可以在以后由服务器处理时使用。 The browser is Internet Explorer, versions 8 and 9.
浏览器是Internet Explorer,版本8和9。
I looked at Silverlight as a possibility but it appears to be too constrained (for security reasons) to be able to get at the information I need to collect. 我认为Silverlight是一种可能性,但它似乎太过限制(出于安全原因)能够获取我需要收集的信息。
So far, searching for an answer hasn't yielded anything yet. 到目前为止,寻找答案还没有产生任何结果。 Any thoughts?
有什么想法吗?
Indeed, you can write a .Net class and instanciate it from JavaScript in IE. 实际上,您可以编写.Net类并在IE中从JavaScript实例化它。
ComVisible
ComVisible
ProgId
ProgId
regasm
regasm
注册.Net程序集 new ActiveXObject
new ActiveXObject
Anyway, there is still a security issue: the user will have to manually allow the ActiveX execution. 无论如何,仍然存在安全问题:用户必须手动允许ActiveX执行。
As I remember, it should be something like that (not tested): 我记得,它应该是那样的(没有经过测试):
In C#: 在C#中:
[ComVisible(true)]
[ProgId("MyCompany.MyClass")]
public class MyClass
{
public string UserName
{
get { return Environment.UserName; }
}
}
In administrator console: 在管理员控制台:
regasm MyClass.dll
In JavaScript: 在JavaScript中:
var myClass = new ActiveXObject("MyCompany.MyClass");
alert(myClass.UserName);
I don't think one can read environment variables from within browsers. 我不认为可以从浏览器中读取环境变量。 Since browsers are designed for the Internet, providing them with an ability to read system's settings of any kind would lead to security issues.
由于浏览器是为Internet设计的,因此为他们提供读取任何类型系统设置的能力会导致安全问题。 Nobody wants a website he/she visiting on the Internet reading his system information right ?
没有人想要他/她在互联网上访问的网站正确阅读他的系统信息吗? I am very skeptical about the possibility of doing the thing you are trying to achieve.
我对做你想要达到的事情的可能性持怀疑态度。 However, you might consider writing a sample windows based app, that gets downloaded from your intranet website, reads the environment settings and submits to the server.
但是,您可以考虑编写一个基于Windows的示例应用程序,该应用程序从您的Intranet网站下载,读取环境设置并提交到服务器。
This should not be possible to do as it is no ones interest(except the bad guys)that you can write programs that access your local computer. 这是不可能做到的,因为你可以编写访问本地计算机的程序并不感兴趣(除了坏人)。
I don't know how many users you have. 我不知道你有多少用户。 But if you definitely need the information, one solution would be to create a program that pulls all the needed data from the computers and stores it in a database mapped to the user.
但是如果您确实需要这些信息,那么一种解决方案就是创建一个程序,从计算机中提取所有需要的数据,并将其存储在映射到用户的数据库中。 Then you will pull the information from the database when you need it in the browser.
然后,您将在浏览器中需要时从数据库中提取信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.