在ashx文件中使用Session和QueryString

原文链接:http://www.cnblogs.com/Spirithero/archive/2011/08/10/2133427.html

有三点需要注意:

1.命名空间中要加入using System.Web.SessionState;

2.接口名要加入IRequiresSessionState或IReadOnlySessionState;

3.不管是Session还是QueryString都要通过HttpContext来获取。

具体代码如下:

view sourceprint?
01 <%@ WebHandler Language="C#" Class="UploadHandler" %>
02   
03 using System;
04 using System.IO;
05 using System.Net;
06 using System.Web;
07 using System.Web.SessionState;
08   
09 public class UploadHandler : IHttpHandler, IRequiresSessionState
10 {
11       
12     public void ProcessRequest (HttpContext context) {
13         context.Response.ContentType = "text/plain";
14         context.Response.Charset = "utf-8";
15   
16         string str1 = context.Session["aaa"].ToString();
17         string str2 = context.Request.QueryString["bbb"].ToString();
18     }
19    
20     public bool IsReusable {
21         get {
22             return false;
23         }
24     }
25   
26 }

 

转载于:https://www.cnblogs.com/Spirithero/archive/2011/08/10/2133427.html

上一篇:ASP.Net一般处理程序Session用法


下一篇:在ashx中使用session