其他分享
首页 > 其他分享> > 在ashx文件中使用Session和QueryString

在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

标签:Web,08,QueryString,System,Session,ashx,context,using,public
来源: https://blog.csdn.net/weixin_30247307/article/details/95051964