获取方法中Session变量 [英] Get Session variable inside a method

查看:164
本文介绍了获取方法中Session变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;
using MySql.Data;
using System.Web.Security;
using System.Data;
using System.IO;
using SurelyKnown.Core;
using System.Configuration;
using System.Collections;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Xml;
using System.Windows.Forms;
public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    [System.Web.Services.WebMethod(EnableSession = true)] 
    public static string[] GetCompletionList(string prefixText, int count, string contextKey)
    {
        int newOrgID = Convert.ToInt32(Session["uOrgID"].ToString());

的错误是在最后一行

The error is on the last line

 CS0120: An object reference is required for the non-static field, method, or property 'System.Web.UI.Page.Session.get'

我应该做的就是在方法内部会话值。

WHat should I do to get the session value inside the method.

推荐答案

使用 HttpContext.Current.Session

int newOrgID=0;
if(HttpContext.Current.Session["uOrgID"]!=null)
{
  int.TryParse(HttpContext.Current.Session["uOrgID"].ToString(),out newOrgID);
}

这篇关于获取方法中Session变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆