ASP.NET(ServerVariables)

出自ProgWiki

跳轉到: 導航, 搜尋

目錄

用途

檔案

info.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="info.aspx.cs" Inherits="info" %>
 
<!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>Info</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" Height="100%" Width="100%">
        </asp:GridView>
    </div>
    </form>
</body>
</html>

info.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
 
public partial class info : System.Web.UI.Page
{
	protected void Page_Load(object sender, EventArgs e)
	{
		using (DataSet objDS = new DataSet())
		{
			DataTable objTable = objDS.Tables.Add("Request.ServerVariables");
			objTable.Columns.Add("VarName");
			objTable.Columns.Add("Value");
 
			foreach (string strKey in this.Request.ServerVariables.AllKeys)
			{
				objTable.Rows.Add(strKey, this.Request.ServerVariables[strKey]);
			}
 
			GridView1.DataSource = objDS;
			GridView1.DataBind();
			GridView1.Caption = objTable.TableName;
		}
	}
}
個人工具
名字空間
變換
動作
導航
分類
其他
技術類News或部落格
工具箱