主要是获取登录用户名,打开IIS,在当前项目上右键选择
属性-->目录安全性-->匿名访问和身份验证控制-->编辑
然后只选择最后一项 [集成Windows身份验证]
获取ServerVariables下面所有的Keys值的方法
属性-->目录安全性-->匿名访问和身份验证控制-->编辑
然后只选择最后一项 [集成Windows身份验证]
If Not Page.IsPostBack Then
Page.Response.Write(Page.Request.ServerVariables("LOGON_USER"))
Page.Response.Write("<br>")
Page.Response.Write(Page.Request.UserHostAddress())
End If
Page.Response.Write(Page.Request.ServerVariables("LOGON_USER"))
Page.Response.Write("<br>")
Page.Response.Write(Page.Request.UserHostAddress())
End If
获取ServerVariables下面所有的Keys值的方法
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Collections.Specialized;
namespace WebApp_CSharp
{
/// <summary>
/// WebForm2 的摘要说明。
/// </summary>
public class WebForm2 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
int loop1, loop2;
NameValueCollection coll;
// Load ServerVariable collection into NameValueCollection object.
coll=Request.ServerVariables;
// Get names of all keys into a string array.
String[] arr1 = coll.AllKeys;
for (loop1 = 0; loop1 < arr1.Length; loop1++)
{
Response.Write("<font color=blue>Key: " + arr1[loop1] + "</font><br>");
String[] arr2=coll.GetValues(arr1[loop1]);
for (loop2 = 0; loop2 < arr2.Length; loop2++)
{
Response.Write("Value " + loop2 + ": " + Server.HtmlEncode(arr2[loop2]) + "<br>");
}
}
}
Web 窗体设计器生成的代码
}
}
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Collections.Specialized;
namespace WebApp_CSharp
{
/// <summary>
/// WebForm2 的摘要说明。
/// </summary>
public class WebForm2 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
int loop1, loop2;
NameValueCollection coll;
// Load ServerVariable collection into NameValueCollection object.
coll=Request.ServerVariables;
// Get names of all keys into a string array.
String[] arr1 = coll.AllKeys;
for (loop1 = 0; loop1 < arr1.Length; loop1++)
{
Response.Write("<font color=blue>Key: " + arr1[loop1] + "</font><br>");
String[] arr2=coll.GetValues(arr1[loop1]);
for (loop2 = 0; loop2 < arr2.Length; loop2++)
{
Response.Write("Value " + loop2 + ": " + Server.HtmlEncode(arr2[loop2]) + "<br>");
}
}
}
Web 窗体设计器生成的代码
}
}