Note that there are some explanatory texts on larger screens.

plurals
  1. POSession State variables aren't working
    primarykey
    data
    text
    <p>I'm writing an ASP.NET C# web site that needs to access data from a database and show it to the user for viewing and editing. The specific data it accesses is based on the user who logs in, and I need for multiple users to be able to use the site simultaneously, viewing and editing different data as they do so. I stumbled upon the concept of Session States, and after a lot of reading and not as much understanding. I've come across a problem.</p> <p>In my default page, I do this to create a Session variable:</p> <pre><code>Session.Add("UserData",userdata); </code></pre> <p>I have also tried this:</p> <pre><code>Session["UserData"] = userdata; </code></pre> <p>Then in a later page, I do this to try to call it:</p> <pre><code>object myobject = Session["UserData"]; </code></pre> <p>This gives me an error, saying that <code>Session["UserData"]</code> is not set to an instance of an object. This is the method everyone seems to be using, is there something I'm missing?</p> <p>My site is configured on IIS to have the Session State Mode set to "In Process", but most people seem to set this manually using their web.config file. However, when I try to do this in my web.config file I am always greeted with "unrecognized configuration section". My compiler doesn't know what this is:</p> <pre><code>&lt;sessionstate mode="inproc"/&gt; </code></pre> <p>EDIT, more detailed code:</p> <pre><code>MyClass userdata = new MyClass(); userdata.name = "myname"; userdata.number = 5; Session["UserData"] = userdata; </code></pre> <p>later...</p> <pre><code>MyClass mydata = (MyClass)(Session["UserData"]); </code></pre> <p>This returns the error that Session["UserData"] is null.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload