All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
asp.net中Server对象的应用实例

Writer: qq Article type: Programming skills(编程技巧) Time: 2014/7/9 1:39:27 Browse times: 255 Comment times: 0

asp.net中Server对象的应用实例


Head photo

Go homepage
Upload pictures
Write articles

asp.net中Server对象的应用实例

Server对象的应用
本节通过一个简单的实例来介绍如何使用Server对象来获得客户端和服务器的相关信息。实例运行结果如图1所示。

图1 Server对象的应用
程序开发步骤如下。
(1)新建一个网站,命名为15_05,其主页默认为Default.aspx。
(2)在Default.aspx页面中添加一个Table表格,用来布局页面,然后在该Table表格中添加5个Label控件,分别用来显示客户端和服务器端的相关信息。
(3)程序主要代码如下。
Default.aspx页面的Page_Load事件中,分别调用Server对象和Request对象的相关属性获取客户端和服务器端信息,并将这些信息显示在相应的Label控件中。Default.aspx页面的Page_Load事件代码如下:
protected void Page_Load(object sender, EventArgs e)
{
Label2.Text = Request.Browser.Platform;
Label3.Text = Request.Browser.Type;
Label5.Text = Server.MachineName.ToLower();
Label1.Text = Request.UserHostAddress;
string hostName = Dns.GetHostName();
IPAddress[] hostip;
hostip = Dns.GetHostAddresses(hostName);
foreach (IPAddress ip in hostip)
{
Label4.Text = ip.ToString();
}
}
完整程序代码如下:
★ ★★★★Default.aspx页面设计文件完整程序代码★★★★★
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>



无标题页







客户端/服务器端信息





&nbsp;&nbsp;
服务器端信息:



&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IP地址:

&nbsp; &nbsp; 计算机名称:


&nbsp;&nbsp;
客户端信息:



&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IP地址:

&nbsp; &nbsp; &nbsp; &nbsp; 操作平台:

&nbsp; &nbsp; 浏览器版本:









★ ★★★★Default.aspx.cs页面代码文件完整程序代码★★★★★
using System;
using System.Data;
using System.Configuration;
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;
using System.Net;
public partial class _Default : System.Web.UI.Page





There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.