Home   Cover Cover Cover Cover
 

Anzeigen von Request-Parametern

Web-Seite

../../solutions/6/RequestInfo.aspx
<%@ Page Language="C#" Inherits="RequestInfo" Src="RequestInfo.aspx.cs" %>
<html>
  <head>
    <title>Information about current request</title>
  </head>
  <body>
    <h2>Information about the current request</h2>
    <form method="post" Runat="server">
      <asp:DataGrid ID="grid" OnLoad="LoadGrid" CellPadding="3"
        AlternatingItemStyle-BackColor="LightGray"
        HeaderStyle-BackColor="Gray" Runat="server"/>
    </form>
  </body>
</html>

Hintergrundcode

../../solutions/6/RequestInfo.aspx.cs
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public class RequestInfo : Page {
  protected DataGrid grid;
  
  public void LoadGrid(object sender, EventArgs e) {
    HttpRequest req = Page.Request;
    HttpBrowserCapabilities browser = req.Browser;

    //----- set up a data table with 2 columns name "variable" and "value"
    DataTable tab = new DataTable();
    tab.Columns.Add(new DataColumn("variable", typeof(string)));
    tab.Columns.Add(new DataColumn("value", typeof(string)));

    //----- fill data table with information
    DataRow row;
    row = tab.NewRow();
    row[0] = "UserHostName";
    row[1] = req.UserHostName;
    tab.Rows.Add(row);

    row = tab.NewRow();
    row[0] = "UserHostAddress";
    row[1] = req.UserHostAddress;
    tab.Rows.Add(row);

    row = tab.NewRow();
    row[0] = "HttpMethod";
    row[1] = req.HttpMethod;
    tab.Rows.Add(row);

    row = tab.NewRow();
    row[0] = "Browser name";
    row[1] = browser.Browser;
    tab.Rows.Add(row);

    row = tab.NewRow();
    row[0] = "Browser type";
    row[1] = browser.Type;
    tab.Rows.Add(row);

    row = tab.NewRow();
    row[0] = "Browser platform";
    row[1] = browser.Platform;
    tab.Rows.Add(row);

    //----- bind the DataView of the data table to the grid
    grid.DataSource = tab.DefaultView;
    grid.DataBind();
  }
}

Ausführung

Klicken Sie hier.