Reputation: 63
If an asp.net static variable eg.
public static string test;
that exists in 2 different web application that share the same application pool, share also the value of their static variables?
if I set the test var in site 1: "test="1""
can I read this from site 2?
Upvotes: 2
Views: 2609
Reputation: 113282
Each server has one or more application pools.
From the application pool, at least one process is started for each asp.net application (and other applications that can run on IIS). One process per asp.net application is the norm, but if you use "web garden" mode, then there can be more than one, each of which behave in isolations (like a mini web-farm, hence "web garden").
Each such process will create an AppDomain, which can host ASP.NET code. It is possible to create other AppDomains on this processes though this isn't often necessary with ASP.NET code (you could for example have your ASP.NET code run some untrusted code in a sandbox AppDomain with reduced privileges, but that's not a common scenario).
Each AppDomain has completely separate copies of all static fields (there's an exception with AppDomain-Neutral assemblies, but ASP.NET only loads mscorlib as AppDomain-neutral).
Therefore static fields are safe to use with ASP.NET, in both normal and web-garden mode.
Upvotes: 2
Reputation: 161783
No, they do not. Static
is only shared across applications in the same AppDomain
.
Upvotes: 8