asp.net - Do all instances of the same ASPX page share the same static field? -
let's consider page's code-behind:
public partial class products : page { private static someclass sharedfield; public product() { // ... logic } }
do products
pages instances share same sharedfield
, know basic concept of static fields. in case, really? users can have access (and can't have own instance of) same static field on website-level?
if so, in aspects used web developer? or non-recommended practice?
yes, there single instance of static field users, within single worker process. if have web farms/web gardens, each have own static instance. if worker process restarts, you'll new static instance.
you'll have use locking around shared field ensure thread safety.
as why use that, i'm not sure, never it. best example can give built-in static httpcontext.current
, gives access request, response, etc.
Comments
Post a Comment