0

I have been having trouble with inProc session variables returning null. The most current is trying to set a Session Variable in the PageLoad of Default. Here is my code.

   string NameNew = Page.User.Identity.Name;
    if (NameNew.Contains('\\'))
    {
        NameNew = NameNew.Split('\\').Last();
    }
    if (Session != null)
    {
        Session["UsersName"] = NameNew;
    }

When debugging it returns System.NullReferenceException: 'Object reference not set to an instance of an object.'

I have tried updating vs, checking IIS express for session issues, moved other session objects to base class. I am at a loss.

7
  • Are you sure this is related to session? Which line exactly is it throwing on, because any of Page.User.Identity.Name could be null and cause this error Commented Mar 19, 2021 at 18:42
  • Session["UsersName"] = NameNew; is throwing the exception. Commented Mar 19, 2021 at 18:43
  • Is Session null at that point? Commented Mar 19, 2021 at 18:46
  • Flydog57 No it's not. Commented Mar 19, 2021 at 18:48
  • It's answered here I bet: stackoverflow.com/questions/5774248/… Commented Mar 19, 2021 at 18:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.