将javascript变量传递给VB.NET sub [英] Pass javascript variable to VB.NET sub

查看:68
本文介绍了将javascript变量传递给VB.NET sub的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将java.从site.master传递到site.master.vb。然后它将成为Page_Load中的id,这样我也可以传递pullLdapData。

我得到了javaID的正确值,我只是无法将它转到sub上以便我可以使用它。



site.master:



函数getUser(){

var wshell = new ActiveXObject(WScript.Shell);

var javaID = wshell.ExpandEnvironmentStrings(%USERNAME%);



};



site.master.vb:

受保护的子Page_Load(发件人为对象,e为EventArgs)处理Me.Load

Dim id,userName

id = javaID

pullLdapData(id,userName)

End Sub



我尝试了什么:



我试过研究过这个但是没有得到任何我在网上找到的建议。

I need to pass javaID from site.master, to site.master.vb. Then it will become id within the Page_Load so that I can pass it too the pullLdapData.
I get the correct value for javaID, I just can not get it over to the sub so that I can use it.

site.master:

function getUser() {
var wshell = new ActiveXObject("WScript.Shell");
var javaID = wshell.ExpandEnvironmentStrings("%USERNAME%");

};

site.master.vb:
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim id, userName
id = javaID
pullLdapData(id, userName)
End Sub

What I have tried:

I have tried researching this and can not get any of the suggestions that I have found online to work.

推荐答案

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.)


这篇关于将javascript变量传递给VB.NET sub的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆