HttpContext.Current
来源:互联网 发布:乔丹数据 编辑:程序博客网 时间:2024/05/17 06:02
1、System.Web.HttpContext.Current:
一般在web应用程序里,你的程序都是为了处理客户端过来的http请求而执行的,当前正在处理的这个请求的一些上下文信息就保存在一个HttpContext对象里,你通过HttpContext的静态属性Current得到当前这个上下文,然后去取你需要的信息,比如查询字符串等。
2、使用其他的对像如:Request,Response, Session, Application, Cookies对象也可用下面的语句取得:
HttpContext.Current.Request
HttpContext.Current.Response
HttpContext.Current.Session
HttpContext.Current.Session["aaa"]
HttpContext.Current.Application
string cookieheader = (string)HttpContext.Current.Application["cookieheader"];
HttpContext.Current.Cookies
在没有继承page的类中,应该这样写
HttpContext.Current.Server
HttpContext.Current.Server.MapPath
Page p=(Page)HttpContext.Current.Handler;
HttpContext.Current.Response
HttpContext.Current.Request
HttpContext.Current.Session
HttpContext.Current.Cookies
HttpContext.Current.Application
HttpContext.Current.Catche
Cookie的写入:
HttpCookie cookie=new HttpCookie("Simple");
cookie.Values.Add("Simple1",HttpUtility.UrlEncode("大叔,你好!"));
cookie.Values.Add("Simple2","English is OK!Nothing we should do!");
Response.AppendCookie(cookie);
Cookie的读取:
HttpCookie cookie=Request.Cookies["Simple"];
string simple1=HttpUtility.UrlDecode(cookie["Simple1"]);
string simple2=cookie["Simple2"];
这样simple1="大叔,你好!";simple2="English is OK!Nothing we should do!";
3、HttpContext.Current.Response.Write()和Response.Write()有什么区别?
MSDN上解释如下:HttpContext.Current.Response为当前 HTTP 响应获取 HttpResponse 对象。Page.Response(也就是第二个)获取与该 Page 对象关联的 HttpResponse 对象。该对象使您得以将 HTTP 响应数据发送到客户端,并包含有关该响应的信息。通常在类中如果该类不继承System.Web.UI.Page类,可以直接用HttpContext.Current.Response,因为Current是静态属性可以直接使用,而Page则需要实例化.
- HttpContext.Current
- HttpContext.Current
- HttpContext.Current
- HttpContext.Current
- HttpContext.Current
- HttpContext.Current.Items用途
- HttpContext.Current.Request.ServerVariables
- HttpContext.Current.Session是什么??
- HttpContext.Current并非无处不在
- HttpContext.Current并非无处不在
- HttpContext.Current并非无处不在
- HttpContext.Current并非无处不在
- HttpContext.Current并非无处不在
- HttpContext.Current.Request.Url
- HttpContext.Current并非无处不在
- 安全地使用HttpContext.Current
- HttpContext.Current并非无处不在
- HttpContext.Current并非无处不在
- layout小结
- APIC 中断属性详解
- lamp配置以及dotprject安装
- stagefright框架(三)-選擇Video Decoder
- WP7 Dev 101 【4】 如何获取用户和手机的信息
- HttpContext.Current
- stagefright框架(四)-Video Buffer傳輸流程
- stagefright框架(五)-Video Rendering
- 解析iphone多线程
- stagefright框架(六)-Audio Playback的流程
- weka
- stagefright框架(七)-Audio和Video的同步
- 成员访问级别
- JDK JRE区别