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的使用:
<script language="c#" runat="server">
void Page_Load(object source,EventArgs e){
if(!(IsPostBack)){
Button1.Text="OK";
DropDownList1.Items.Add("http://www.sohu.com");
DropDownList1.Items.Add("http://www.sina.com.cn");
DropDownList1.Items.Add("http://www.163.com");
}
}
public void Click(object o,EventArgs e){
Response.Redirect(DropDownList1.SelectedItem.Text);
}
</script>
<form runat="server">
<asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>
<asp:Button ID="Button1" runat="server" OnClick="Click" Text=""/>
</form>
二、asp.net的核心对象
1、Request对象:
部分属性:
ApplicationPath
Path
PhysicalApplicationPath
Browser
Cookies
IsSecureConnection
RequestType
QueryString
Url
Rawurl
UserHostName
UserHostAddress
UserLanguages
下面是一个检查这些属性的小例子:
<% Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" %>
<script Language="C#" runat="server">
void Page_Load(Object Src, EventArgs E)
{
if (!IsPostBack) {
if(Request.Browser.Browser=="IE")
{
if(Request.Browser.MajorVersion<6){
Label1.Text="Time to update your Ietnet Explore !";
}
else{
Label1.Text="小子很吊呀,早就用上最新的浏览器了!";
}
}
else
{
Label1.Text="Your Browser is "+Request.Browser.Browser+" !";
}
}
}
</script>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<asp:Label ID="Label1" runat="server" Text="" />
</body>
</html>
2、Response对象
以下几个属性和方法:
Buffer
ContentType
Cookies
Clear()
Flush()
End()
Redirect()
Write()
WriteFile()
下面是一个形象的例子:
<% Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>无标题文档</title>
</head>
<body>
<%
for(int i=0;i<50000;i++){
Response.Write("X");
if(i%300==0)
Response.Write("
");
}
%>
</body>
</html>
<% Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>无标题文档</title>
</head>
<body>
<%
Response.Buffer=false;
for(int i=0;i<50000;i++){
Response.Write("X");
if(i%300==0)
Response.Write("
");
}
%>
</body>
</html>
这两段代码十分想象,但是运行差别却是非常明显的。
3、server对象
MachineName
ScriptTimeOut
HtmlEncode()
HtmlDecode()
MapPath()
UrlEncode()
UrlDecode()
坚持学asp.net——(十)
80酷酷网 80kuku.com