首页 新闻 会员 周边

Ashx继承IHttpHandler,IRequiresSessionState两个接口后依然无法访问session

0
悬赏园豆:20 [已解决问题] 解决于 2014-09-15 11:44
    public int getValue(string type)
    {
        int res=0;
        if (type == "current")
        {
            if (HttpContext.Current.Session["current"] == null)
            {
                HttpContext.Current.Session.Add("current", 0);
            }
            res = int.Parse(HttpContext.Current.Session["current"].ToString());
        }
        if (type == "total")
        {
            if (HttpContext.Current.Session["total"] == null)
            {
                HttpContext.Current.Session.Add("total", 1);
            }
            res = int.Parse(HttpContext.Current.Session["total"].ToString());
        }
        return res;
    }

如上面的代码,每次访问或者是修改session的值都会为空。可以又能添加进去

Miky.Chou的主页 Miky.Chou | 初学一级 | 园豆:76
提问于:2013-10-12 11:13
< >
分享
最佳答案
0
收获园豆:20
happydaily | 菜鸟二级 |园豆:253 | 2013-10-12 11:15

谢谢关注。

看以上的文章应该可能是我的多线程访问有问题。 可是应该如何修正呢?

Miky.Chou | 园豆:76 (初学一级) | 2013-10-12 11:28

@Miky.Chou: 用context.Session[] ,多线程要请高手指导了

happydaily | 园豆:253 (菜鸟二级) | 2013-10-12 14:35

@happydaily: 嗯,我即使吧context传入也是一样的。

Miky.Chou | 园豆:76 (初学一级) | 2013-10-13 21:45
其他回答(2)
0

咦,我一直都是用context.Session[] 呀。。。

allon6318 | 园豆:858 (小虾三级) | 2013-10-14 18:01

嗯,单线程没问题。多线程就会有问题了

支持(0) 反对(0) Miky.Chou | 园豆:76 (初学一级) | 2013-10-16 16:12
0

无法解决的,全服务器只能一个

Miky.Chou | 园豆:76 (初学一级) | 2013-10-23 14:38
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册