我在内部有一个简单的 HTML 页面,它只显示一个表单并要求用户填写它。我想自动捕获 windows 域用户名和机器名,以将其与表单中收集的数据一起提交。
我可以在客户端这样做吗?HTML?JavaScript?或者我是否被迫在服务器端做(我不知道该怎么做......但是)
用户有XP和7机器和IE7,8。
顺便说一句,我找到了这篇文章,但我不得不承认我不知道你会在页面的哪个位置输入那个“代码”。
这是我正在使用的代码不起作用。它调用 JavaScript 函数,并"Username="
在下一行显示 and "Done."
,但不显示用户名。
如果使用 Chrome,它会显示<%HttpContext.Current.User.Identity.Name%>
.
<html lang="en">
<head>
<script>
function get_user_Name() {
var username = '<%HttpContext.Current.User.Identity.Name%>';
document.write("Username=");
document.write(username);
document.write(" <br> Done.");
}
</script>
<meta charset="utf-8" />
<title>Training and Development Site</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
</head>
<body>
<a href="add-number-to-dnc.html">Add Phone Number to Dialer Do Not Call list</a>
<br><br>
<button type="button" onclick="get_user_Name()">Display User Name</button>
</body>
</html>
另外 -我正在使用 WebMatrix / IIS7 Express