基本对象常用方法及属性

Request对象

QuertString属性   对应get方法附加在url后的数据

Form属性        对应post方法的数据

ServerVariables属性     获取web服务器变量

Exp

Request.ServerVariables["HTTP_USER_AGENT"];

//获取浏览器及版本

Request.ServerVariables["HTTP_ACCEPT_LANGUAGE"];

//获取浏览器语言

 

Params属性            以上方式传输内容都可以使用该属性获取

 

Response对象

Write方法      直接输出

Redirect方法          重定向

 

Page.IsPostBack是否首次加载  

 

Page.IsCrossPagePostBack是否跨页回发

Exp

//发出提交的页面按钮控件:

<asp:Button ID="btnOk" runat="server" 

                   PostBackUrl="~/PostBack.aspx" Text="查询" />

 

//获取内容页面的判断

if (Page.PreviousPage!=null)

{

         if(PreviousPage.IsCrossPagePostBack == true)

         {

                 //FindControl方法获得指定控件

             this.lblShowURL.Text = "您的查询条件为:" +

              ((TextBox)this.PreviousPage.FindControl("txtKeyWord")).Text;

         }

}

 

Session

Exp:

存入:

//User为一个类包含名字和密码2个字段

User user = new User();

user.Id = 0;

user.UserName = txtloginId.Text;

user.PassWord = txtLoginPwd.Text;

Session["User"] = user;

 

取出:

User userTemp = new User();

userTemp  =  Session["User"]  as  User

 

Cookies

Exp1:

存入:

HttpCookie hcCookie = new HttpCookie("UserName", “张三");

Response.Cookies.Add(hcCookie);

 

取出:

string UserName=Request.Cookies["UserName"].Value;

 

Exp2:

存入:

HttpCookies  objCookies =  new  HttpCookies”UserInfo”;

objCookies.Values[“ID”] = “007”;

objCookies.Values[“name”] = “jams”;

Response.Cookies.Add(objCookies);

 

取出:

String  id  =  Request.Cookies["UserInfo"][“ID”].ToString();

 

Exp3

//持久化保存

userCookie.Expires = DateTime.Now.AddDays(30);

 

Application

Application.Lock();

Application[“usercount”] = 0;

Application.UnLock();

 

Add() Clear()Remove()等方法

posted @ 2008-10-25 00:41  Edward Xie  阅读(156)  评论(0编辑  收藏  举报