使用C#ASP.NET访问环境变量 [英] Accessing environmental variables with C# ASP.NET
本文介绍了使用C#ASP.NET访问环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我有一个应用程序,它使用来自用户计算机的一些数据(通过类System.Environment访问)
具体来说我需要System.Environment.UserName和System .Environment.UserDomainName。是否可以从C#ASP.NET网页中访问该数据?如果是的话 - 该方法应该是什么?
提前谢谢!
Hello,
I have an app which uses some data from user computer (accessed via class System.Environment)
Specifically I need System.Environment.UserName and System.Environment.UserDomainName. Is it possible to access that data from within C# ASP.NET web-page? If so - what should be the approach?
Thank you in advance!
推荐答案
http://forums.asp.net/t/prev/1540391 [ ^ ]
请参阅链接,尤其是文章的最后部分。
系统信息 [ ^ ]
Refer the link , especially the last part of the Article.
System Information[^]
如果我让你纠正,那就试试这样吧
.aspx Page
If I got you correctlt then try like this
.aspx Page
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="envornment.aspx.cs" Inherits="TestApplication.envornment" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
User Name :
<asp:Label ID="lblUserName" runat="server"></asp:Label>
<br />
User Domain Name :
<asp:Label ID="lblUserDomainName" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
.aspx.cs Page
.aspx.cs Page
using System;
namespace TestApplication
{
public partial class envornment : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblUserName.Text = Request.ServerVariables["REMOTE_USER"];
lblUserDomainName.Text = Request.ServerVariables["REMOTE_ADDR"];
}
}
}
这篇关于使用C#ASP.NET访问环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文