Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your approach is almost certainly a bad idea.</p> <p>A shared variable is instantiated <em>once</em> for your application, and retains the last value that was put in it, for any thread that accesses it. Carefully consider any code that is relying on the value of the variable - modifications to the value could be happening at <em>any time</em>, between any two lines of code, from any thread that is executing code that might modify it.</p> <p><code>Shared</code> doesn't have anything to do with visibility to end users <em>per se</em>. <code>Shared</code> means that there is only one instance of that variable, so every request that instantiates a <code>myPage</code> class will use the <em>exact same memory</em> for their Variable1 and array1 references. The <code>Protected</code> modifier ensures that no classes other than <code>myPage</code> or derivative classes can see and modify the variables, but any users executing a request that uses a <code>myPage</code> will certainly be using the same variable reference - and hence changing the value for any other users.</p> <p>If you want to maintain values of a variable for a user's session, use the <code>Session</code> object, that's exactly what it's for.</p> <pre><code>Session["Variable1"] = "usersProtectedString"; </code></pre> <p>If you want to maintain values for all users across the entire application, use the <code>Application</code> object. </p> <pre><code>Application.Lock(); Application["Variable1"] = "stringForAllUsers"; Application.Unlock(); </code></pre>
 

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