苏起 - 云代码空间
—— 干一件你感兴趣的事,永远不觉得累!
//在ashx文件中读写session
//晕S,终于搞定在ashx中输出验证码,在保存验证码时竟然读不到session
//错误提示:未将对象引用设置到对象的实例。
//查找资料终于搞定....
//首先要继承 System.Web.SessionState.IReadOnlySessionState 的接口
//其中:System.Web.SessionState.IReadOnlySessionState为只读会话的接口
//而:System.Web.SessionState.IRequiresSessionState 为可读可写会话的接口,这个看情况而继承吧~~~
代码如下:
using System
using System.Web
using System.Web.SessionState
Public Class myVerifyCode : Implements IHttpHandler, IRequiresSessionState
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
context.Session("VerifyCode") = "登陆成功"
context.Response.Write(context.Session("VerifyCode"))
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return True
End Get
End Property
End Class