All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
Visual C++ 6.0教程:Visual C++ 6.0概述
js版sliderBar(滑动条)控件_JavaScript技术_编程技术
Asp.net生成静态网页的实现代码_[Asp.Net教程]
ASP.NET,Atlas简单控件介绍之界面控件_[Asp.Net教程]
利用C#来做ASP.NET的登陆页面_[Asp.Net教程]
Linux下Tomcat与Apache,Web服务器的整合_php资料_编程技术
SQL,Server,2000安装故障_[SQL,Server教程]
在GridView中实现数据并列显示_[Asp.Net教程]
ASP.NET,2.0中使用样式、主题和皮肤_.net资料_编程技术
ASP.NET,MVC+LINQ开发一个图书销售站点(9)-编辑目录_[Asp.Net教程]
Reading number is top 10 pictures
Startling Russian girl blind date scene1
The money of more than 100 countries and regions20
A man's favorite things10
Plump, too plump!1
The household of rural style is designed
Chinese paper-cut grilles art appreciation2
Japanese snow monkeys in the hot spring to keep warm, close their eyes to enjoy
赵惟依写真3
2012 national geographic daily picture2
做运动的校花2
Download software ranking
The Bermuda triangle3
Boxer vs Yellow2
Tram sex maniac 2 (H) rar bag17
Ashlynn Video2
Red cliff
dreamweaver8中文版
Boxer vs Yellow4
JSP+Ajax Web development typical examples
jdk1.6 for windows
双旗镇刀客B
qq published in(发表于) 2014/7/9 1:36:23 Edit(编辑)
asp.net2.0中Server对象的方法和属性

asp.net2.0中Server对象的方法和属性

asp.net2.0中Server对象的方法和属性

Server对象的属性

Server对象常用属性及说明如表1所示。



表1 Server对象常用属性及说明

下面对比较重要的属性进行详细介绍。

MachineName属性。用来获取服务器的计算机名称。

* 示例

使用MachineName属性获取服务器名称

本示例实现的是,当程序运行时,在页面Default.aspx中显示服务器名称。示例运行结果如图1所示。



图1 使用MachineName属性获取服务器名称

程序代码如下。

在Default.aspx页面的Page_Load事件中,调用Server对象的MachineName属性获取服务器名称,然后使用ToLower方法将得到的服务器名称转换为小写,在Label控件中显示出来,实现代码如下:

protected void Page_Load(object sender, EventArgs e)

{

Label1.Text = Server.MachineName.ToLower();

}

完整程序代码如下:

★ ★★★★Default.aspx代码文件完整程序代码★★★★★

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>







无标题页









服务器名称:








★ ★★★★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;

public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

Label1.Text = Server.MachineName.ToLower();

}

}

Server对象的方法

Server对象常用方法及说明如表1所示。



表2Server对象常用方法及说明

下面对比较重要的方法进行详细介绍。

(1)HtmlDecode和HtmlEncode方法。HtmlDecode方法用于对HTML编码的字符串进行解码,并返回已解码的字符串。

语法:

public string HtmlDecode (string s)

参数说明如下。

s:要解码的HTML字符串。

返回值:已解码的文本。

HtmlEncode方法用于对字符串进行HTML编码,并返回已编码的字符串。

语法:

public string HtmlEncode (string s)

参数说明如下。

s:要编码的文本字符串。

返回值:已使用HTML编码的文本。

* 示例

使用HtmlDecode和HtmlEncode方法编码相同字符串

本示例实现的是当程序运行时,在页面Default.aspx中分别输出使用Server对象的HtmlEncode方法和HtmlDecode方法解码和编码的相同字符串。示例运行结果如图1所示。



图2 使用HtmlDecode和HtmlEncode方法编码相同字符串

程序代码如下。

在Default.aspx页面的Page_Load事件中,分别调用Server对象的HtmlEncode方法和HtmlDecode方法对相同的字符串进行编码和解码,然后在页面中输出,实现代码如下:

protected void Page_Load(object sender, EventArgs e)

{

Response.Write("使用HtmlEncode方法为指定字符串编码:" + Server.HtmlEncode("浏览器中字符串") + "
"

+ "使用HtmlDecode方法为指定字符串解码:" + Server.HtmlDecode("浏览器中字符串"));



添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.