解决ashx文件下的Session“未将对象引用设置到对象的实例”
2013-09-21 11:25
357 查看
using System; using System.Collections.Generic; using System.Linq; using System.Web; using PPT_DAL; namespace PPT_Web.tool { /// <summary> /// Login 的摘要说明 /// </summary> public class Login : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/html"; string lo_usm = context.Request.Params["lo_usm"]; string lo_pwd = context.Request.Params["lo_pwd"]; UserEntity userModel = PPT_BLL.UserManager.Login(lo_usm,lo_pwd); if (userModel != null) { context.Session["UserId"] = userModel.USR_ID; context.Response.Write("{'result':'1'}"); } else { context.Response.Write("{'result':'0'}"); } } public bool IsReusable { get { return false; } } } }
问题:
如题所示,在一般处理程序文件,即ashx文件下调用Session["UserId"],当调试的时候会显示“未将对象实例化的”的错误解决方法:
将该类实现“IRequiresSessionState”的接口即可,而此接口在System.Web.SessionState命名空间下,所以要在上面添加一句:using System.Web.SessionState;最终实现代码如下:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using PPT_DAL; using System.Web.SessionState; namespace PPT_Web.tool { /// <summary> /// Login 的摘要说明 /// </summary> public class Login : IHttpHandler, IRequiresSessionState { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/html"; string lo_usm = context.Request.Params["lo_usm"]; string lo_pwd = context.Request.Params["lo_pwd"]; UserEntity userModel = PPT_BLL.UserManager.Login(lo_usm,lo_pwd); if (userModel != null) { context.Session["UserId"] = userModel.USR_ID; context.Response.Write("{'result':'1'}"); } else { context.Response.Write("{'result':'0'}"); } } public bool IsReusable { get { return false; } } } }
相关文章推荐
- C#一般处理程序设置和读取session(session报错未将对象引用设置到对象的实例解决)
- ashx文件中使用session提示“未将对象引用设置到对象的实例”
- 解决报错:Session为空(未将对象引用设置到对象的实例)
- C#一般处理程序设置和读取session(session报错“未将对象引用设置到对象的实例”解决)
- ashx和session解决未将对象引用设置到对象的实例问题
- ashx文件中使用session提示“未将对象引用设置到对象的实例”的解决方法
- 未将对象引用设置到对象的实例的解决办法
- 解决使用DevExpress开发错误:未将对象引用设置到对象的实例
- asp.net运行提示未将对象引用设置到对象的实例错误解决方法
- Dynamics CRM 安装CRM程序系统检查界面报未将对象引用设置到对象的实例的解决方法
- VS2015 新建项目提示 未将对象引用设置到对象的实例 解决方法
- Web页面设计时提示"创建控件出错,未将对象引用设置到对象的实例”的错误解决办法
- Dynamics CRM 安装CRM程序系统检查界面报未将对象引用设置到对象的实例的解决方法
- 出现“未将对象引用设置到对象的实例” 错误2010-09-16 19:07解决办法
- ashx页面中 Session值出现“未将对象引用设置到对象的实例”错误
- 未将对象引用设置到对象的实例 解决办法
- 写入Session时出现未将对象引用设置到实例上
- 使用FindControl出现未将对象引用设置到对象的实例 错误的解决办法
- Dynamics CRM 安装CRM程序系统检查界面报未将对象引用设置到对象的实例的解决方法
- 未将对象引用设置到对象的实例 解决办法