在ashx文件中读写session
晕S,终于搞定在ashx中输出验证码,在保存验证码时竟然读不到session
错误提示:未将对象引用设置到对象的实例。
查找资料终于搞定....
首先要继承 System.Web.SessionState.IReadOnlySessionState 的接口
其中:System.Web.SessionState.IReadOnlySessionState为只读会话的接口
而:System.Web.SessionState.IRequiresSessionState 为可读可写会话的接口,这个看情况而继承吧~~~
代码如下:
1Imports System
2Imports System.Web
3Imports System.Web.SessionState
4Public Class myVerifyCode : Implements IHttpHandler, IRequiresSessionState
5
6
7 Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
8.
9 context.Session("VerifyCode") = "登陆成功"
10 context.Response.Write(context.Session("VerifyCode"))
11.
12 End Sub
13
14 Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
15 Get
16 Return True
17 End Get
18 End Property
19
20End Class
21
2Imports System.Web
3Imports System.Web.SessionState
4Public Class myVerifyCode : Implements IHttpHandler, IRequiresSessionState
5
6
7 Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
8.
9 context.Session("VerifyCode") = "登陆成功"
10 context.Response.Write(context.Session("VerifyCode"))
11.
12 End Sub
13
14 Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
15 Get
16 Return True
17 End Get
18 End Property
19
20End Class
21
睡觉啦,苦命的编程员...555~~~