在Ajax中有时会使用到Session,在aspx.cs文件这样获取:

 string name = Session["name"];

但是在Ajax中就不能这样获取Session,必须实现Session接口,如下

<%@ WebHandler Language="C#" class="msg" %>

using System;
using System.Web;
using Model;
using service;

public class msg : IHttpHandler,System.Web.SessionState.IRequiresSessionState  {//红色的就是实现Session接口
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";      

        string vali_code =context.Session["vcode"].ToString().Trim(); 
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}

相关文章:

  • 2021-09-07
  • 2021-12-30
  • 2022-12-23
  • 2021-10-25
  • 2022-12-23
  • 2021-09-18
  • 2021-04-30
  • 2021-05-29
猜你喜欢
  • 2022-12-23
  • 2021-10-01
  • 2021-06-24
  • 2022-01-05
  • 2021-11-13
相关资源
相似解决方案