zoukankan      html  css  js  c++  java
  • 一般处理程序(.ashx)中使用Session

    最近做一个项目,有使用Ajax调用ashx文件 ,其中ashx文件里面有用到Session,但是总无法获取Session,经过调试,出现的错误的原因:

    大体如下

    Session["loginName"]为空,无法toString();

    context.Session["Id"]

    “context.Session”引发了“System.NullReferenceException”类型的异常

    base {System.SystemException}: {"该方法的指针为空。"} 

    查阅MSDN得到ashx文件要使用Session,必须实现Session接口; 

    using System;
    using System.Web;
    using System.Web.SessionState;     //第一步:导入此命名空间

    public class checkCookie : IHttpHandler ,IRequiresSessionState   //第二步:实现接口    到此就可以像平时一样用Session了
    ...{
        
        public void ProcessRequest (HttpContext context) 
        ...{
  • 相关阅读:
    Ubuntu
    VSCode
    VSCode
    Astyle
    Qt
    待办
    Qt
    Qt
    Qt
    python pip常用命令、配置pip源
  • 原文地址:https://www.cnblogs.com/slu182/p/4081548.html
Copyright © 2011-2022 走看看