मैं निर्धारित करने के लिए अगर एक Session
चर मौजूद है कोशिश कर रहा हूँ, लेकिन मैं त्रुटि हो रही है:का पता नहीं लगा सकते हैं सत्र चर मौजूद है या नहीं
System.NullReferenceException: Object reference not set to an instance of an object.
कोड:
// Check if the "company_path" exists in the Session context
if (System.Web.HttpContext.Current.Session["company_path"].ToString() != null)
{
// Session exists, set it
company_path = System.Web.HttpContext.Current.Session["company_path"].ToString();
}
else
{
// Session doesn't exist, set it to the default
company_path = "/reflex/SMD";
}
क्योंकि है कि Session
नाम "company_path" मौजूद नहीं है, लेकिन मैं इसका पता नहीं लगा सकता!
उत्तर के लिए धन्यवाद, मुझे अभी भी एक ही त्रुटि मिल रही है हालांकि – Luke
के साथ जांचें कि आपका वर्तमान थ्रेड System.Web.HttpContext तक पहुंच सकता है या नहीं? – Adil
मैं इसे कैसे देखूं? मेरे पास System.Web' का उपयोग कर रहा है? क्या यह सही है? – Luke