用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字

苏起    -  云代码空间

—— 干一件你感兴趣的事,永远不觉得累!

asxh中读取Session值为空引用问题

2014-05-27|1945阅||

摘要:asxh Session

//在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

顶 0踩 0收藏
文章评论
    发表评论