In an MVC project, trying to access one of the session variables in the View page.
var command = new SqlCommand(query, conn);
conn.Open();
Session["username"] = "swe12387";
command.ExecuteNonQuery();
In the above case, the value of the Session variable is as expected.
But in the below case, the session variable is null.
var command = new SqlCommand(query, conn);
conn.Open();
command.ExecuteNonQuery();
Session["username"] = "swe12387";
What would the problem be? Could running a query be making any change in the session state? Thanks in advance.