.NET开发

本类阅读TOP10

·NHibernate快速指南(翻译)
·vs.net 2005中文版下载地址收藏
·【小技巧】一个判断session是否过期的小技巧
·VB/ASP 调用 SQL Server 的存储过程
·?dos下编译.net程序找不到csc.exe文件
·通过Web Services上传和下载文件
·学习笔记(补)《.NET框架程序设计(修订版)》--目录
·VB.NET实现DirectDraw9 (2) 动画
·VB.NET实现DirectDraw9 (1) 托管的DDraw
·建站框架规范书之——文件命名

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
坚持学asp.net——(十)

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

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("<br>");
 }
%>
</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("<br>");
 }
%>
</body>
</html>

这两段代码十分想象,但是运行差别却是非常明显的。

3、server对象

MachineName

ScriptTimeOut

HtmlEncode()

HtmlDecode()

MapPath()

UrlEncode()

UrlDecode()




相关文章

相关软件