C#一般处理程序 ashx.cs使用Session报错问题

 1 HttpContext.Current.Session["UserID"].ToString();//报错,报Session为Null,
 2 
 3 此时需要添加引用和继承IRequiresSessionState接口。
 4  需要引用程序集System.Web的引用
 5 using System.Web.SessionState;添加命名空间的引用  
 6 
 7 
 8 public class DownloadHandler : IHttpHandler,  IReadOnlySessionState 
 9 {
10   HttpContext.Current.Session["UserID"].ToString(); 在此处使用Session就不会报错了。
11 }
12 
13 到此问题解决,就是这么简单。
14 
15 
16  
原文地址:https://www.cnblogs.com/softwaredeveloper/p/5355459.html