Asp.net在ashx文件中处理Session问题解决方法
今天做一个vb.的登录实例,前台使用Ext中Ajax ,后台用ashx文件处理登录过程,并将用户储存在Session中总是出现在这个错误. [NullReferenceException: 未将对象引用设置到对象的实例。]
从网上查了一下有以下几种原因:
1、ViewState 对象为Unll。
2、DateSet 空。
3、sql语句或Datebase的原因导致DataReader空。
4、声明字符串变量时未赋空值就应用变量。
5、未用new初始化对象。
6、Session对象为空。
开始以为是 Session对象为空的原因:将代码修改以下
if context.Session.isNewSession then
context.Session("UserName")=username 'username为接受的用户名
.................
这样修改了以后,晕!!!!!,还是相同的错误.再Google吧
输入:ashx 处理 session 中于搜到了,太不容易,看来搜索也需要很多技巧
原来:在 ashx 中要使用Session ,需要继承System.Web.SessionState.IRequiresSessionState接口.默认的之继承了IHttpHandler接口
OK 直接看源代码吧
<%@ WebHandler Language="VB" Class="logout" %>
Imports System
Imports System.Web
Imports System.Web.SessionState
Public Class logout : Implements IHttpHandler, IRequiresSessionState
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
context.Session.Clear()
context.Response.Write("{'suess':'true'}") 'JSON格式数据
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程