Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Session variable inside a method

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.

like image 695
Mark Avatar asked Oct 17 '11 12:10

Mark


1 Answers

Use HttpContext.Current.Session

int newOrgID=0;
if(HttpContext.Current.Session["uOrgID"]!=null)
{
  int.TryParse(HttpContext.Current.Session["uOrgID"].ToString(),out newOrgID);
}
like image 181
KV Prajapati Avatar answered Sep 19 '22 21:09

KV Prajapati