且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将javascript变量传递给VB.NET sub

更新时间:2023-02-17 21:12:57

ActiveX对象只能在Windows上的Internet Explorer中使用。 />


此外, WScript.Shell ActiveX对象仅在用户修改其设置以允许ActiveX脚本编写时才有效没有标记为安全的脚本的对象。



最后,你显然不明白ASP.NET是如何工作的。在将任何HTML或Javascript发送到客户端之前, Page_Load 事件在服务器上运行。在服务器端代码完成之前,Javascript不会运行,并且呈现的HTML已经返回给客户端。





您需要忘记Javascript,并打开 Windows身份验证 [ ^ ]。然后,用户可以使用网络上的凭据登录您的站点,并且您将能够使用 User.Identity.Name 属性来检索其用户名。



如果用户与您的服务器位于同一网络,他们甚至可以将您的网站添加到IE的本地Intranet区域,IE和Chrome都会自动进行身份验证到您的站点,而无需用户重新键入其凭据。 (对于Firefox,您需要更改高级设置 [ ^ ]以获得此行为。)
ActiveX objects will only work in Internet Explorer on Windows.

Furthermore, the WScript.Shell ActiveX object will only work if the user has modified their settings to allow scripting of ActiveX objects not marked as "safe for scripting".

And finally, you clearly don't understand how ASP.NET works. The Page_Load event runs on the server, before any HTML or Javascript has been sent to the client. The Javascript doesn't run until the server-side code has finished, and the rendered HTML has been returned to the client.


You need to forget the Javascript, and turn on Windows Authentication[^]. Users will then be able to sign in to your site using their credentials on your network, and you will be able to use the User.Identity.Name property to retrieve their username.

If the users are on the same network as your server, they can even add your site to IE's "Local Intranet" zone, and both IE and Chrome will automatically authenticate to your site without requiring the user to re-type their credentials. (For Firefox, you need to change an advanced setting[^] to get this behaviour.)