【问题标题】:How to modify the session variable inside the asp.net webmethod如何修改asp.net webmethod中的会话变量
【发布时间】:2013-11-22 15:18:19
【问题描述】:

我有以下 webmethod,我想修改现有 Session 变量的值,但在 webmethod 内部,每当我将值分配给该会话变量时,该值并未分配给它。

网络方法

 [WebMethod(EnableSession = true)]
    public static List<tblCustomerList> CustData(String id)
    {
        Int32 count=(Int32) HttpContext.Current.Session["pgnum"];
        HttpContext.Current.Session["pgnum"] = count++;
        DataGridEntities _dbContext = new DataGridEntities();
        var filteredResult = _dbContext.tblCustomerLists.ToList();
        return filteredResult;
    }

【问题讨论】:

  • 不应该使用 ++count ,不赋值是什么意思

标签: asp.net ajax c#-4.0 session


【解决方案1】:

在你的代码中你应该这样做,因为 count++ 将分配现有的值,然后增加它的值

          HttpContext.Current.Session["pgnum"] = ++count;      

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-02
    • 1970-01-01
    • 1970-01-01
    • 2011-11-09
    • 1970-01-01
    • 2012-03-26
    • 1970-01-01
    • 2018-05-20
    相关资源
    最近更新 更多