Introduction
Get the name of the person who is active in the windows environment. ASP.NET provides simple property for this type of query. Use UserName property of the Environment class which is reside in System namespace.Application of the property is
- Divide the application in different users also check who is online in current thread.
Example
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = Environment.UserName; ;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<span style="color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none;">
Get the name of the person who is active in the windows environment.<br />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Get user name" Width="135px" />
<br />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
<br />
</span>
</div>
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = Environment.UserName; ;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<span style="color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none;">
Get the name of the person who is active in the windows environment.<br />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Get user name" Width="135px" />
<br />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
<br />
</span>
</div>
</form>
</body>
</html>
Tidak ada komentar:
Posting Komentar