ajax 处理页面 Session接收值为空时如何处理

引用 using System.Web.SessionState;

接口IRequiresSessionState

 

实例

<%@ WebHandler Language="C#" Class="ShanChu" %>

using System;
using System.Web;
using System.Data;
using System.Data.Linq;
using System.Linq;
using System.Collections.Generic;
using System.Web.SessionState;

public class ShanChu : IHttpHandler,IRequiresSessionState
{
    
    public void ProcessRequest (HttpContext context) {
        string goodid = context.Request["goodid"].ToString();

        List<Order_Goods> list = context.Session["ShuJU"] as List<Order_Goods>;

        var query = list.Where(p => p.GoodsID == goodid);
        if (query.Count() > 0)
        {
            Order_Goods data = query.First();
            list.Remove(data);

        }
       
       string count = list.Count.ToString();
       context.Session["ShuJU"] = list;
       context.Response.Write(count);
      
        
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}

 

posted @ 2015-11-13 10:19  断肠人—断肠人  阅读(507)  评论(0编辑  收藏  举报