asp.net中的对象
一、命名空间
只是一个形象的代号,能够粗略表达其中类的情况。
下面列举在使用asp.net创建web程序时最常用的命名空间:
System.Web;System.Web.Ui;System.IO;System.Collections;System.Diagnostics;System.Date;System.Globalization;System.Drawing;System.Xml
Response.Redirect的使用:
1<script language="c#" runat="server">
2
3void Page_Load(object source,EventArgs e){
4
5if(!(IsPostBack)){
6
7Button1.Text="OK";
8DropDownList1.Items.Add(" http://www.sohu.com ");
9DropDownList1.Items.Add(" http://www.sina.com.cn ");
10DropDownList1.Items.Add(" http://www.163.com ");
11
12}
13
14}
15public void Click(object o,EventArgs e){
16
17Response.Redirect(DropDownList1.SelectedItem.Text);
18
19}
20</script>
1<form runat="server">
2<asp:dropdownlist id="DropDownList1" runat="server"></asp:dropdownlist>
3<asp:button id="Button1" onclick="Click" runat="server" text=""></asp:button>
4</form>
二、asp.net的核心对象
1、Request对象:
部分属性:
ApplicationPath
Path
PhysicalApplicationPath
Browser
Cookies
IsSecureConnection
RequestType
QueryString
Url
Rawurl
UserHostName
UserHostAddress
UserLanguages
下面是一个检查这些属性的小例子:
1@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312"
1<script language="C#" runat="server">
2void Page_Load(Object Src, EventArgs E)
3{
4if (!IsPostBack) {
5if(Request.Browser.Browser=="IE")
6{
7if(Request.Browser.MajorVersion<6){
8Label1.Text="Time to update your Ietnet Explore !";
9}
10else{
11Label1.Text="小子很吊呀,早就用上最新的浏览器了!";
12}
13}
14else
15{
16Label1.Text="Your Browser is "+Request.Browser.Browser+" !";
17}
18}
19}
20</script>
1<html xmlns=" http://www.w3.org/1999/xhtml ">
2<head>
3<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
4<title>无标题文档</title>
5</head>
6<body>
7<asp:label id="Label1" runat="server" text=""></asp:label>
8</body>
9</html>
2、Response对象
以下几个属性和方法:
Buffer
ContentType
Cookies
Clear()
Flush()
End()
Redirect()
Write()
WriteFile()
下面是一个形象的例子:
1@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312"
1<html xmlns=" http://www.w3.org/1999/xhtml ">
2<head>
3<title>无标题文档</title>
4</head>
5<body>
for(int i=0;i<50000;i++){
Response.Write("X");
if(i%300==0)
Response.Write("<br/>");
}
1</body>
2</html>
1@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312"
1<html xmlns=" http://www.w3.org/1999/xhtml ">
2<head>
3<title>无标题文档</title>
4</head>
5<body>
Response.Buffer=false;
for(int i=0;i<50000;i++){
Response.Write("X");
if(i%300==0)
Response.Write("<br/>");
}
1</body>
2</html>
这两段代码十分想象,但是运行差别却是非常明显的。
3、server对象
MachineName
ScriptTimeOut
HtmlEncode()
HtmlDecode()
MapPath()
UrlEncode()
UrlDecode()