在日常学习和使用ASP.NET的过程中,有些比较特殊有用的经验收集在这里,方便自己记忆和理解,也希望能帮助到一些初学者参考。如果有些不足的地方希望高手不吝赐教!!!
一、在一般处理文件(ashx)中使用Session时,需要引进命名空间:using System.Web.SessionState; 并且使该类实现IRequiresSessionState接口,然后就能通过HttpContext.Current.Session使用Session了!
简易代码如下:
using System.Web.SessionState;
........
public class Handler : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
HttpContext.Current.Session["user"] = "luoyisheng";
}
public bool IsReusable
{
get
{
return false;
}
}
}