When do asp.net role providers live and die?

I work with a custom role provider in asp.net, and it seems that after the provider is loaded into memory, it does not drop out of memory until the web application restarts (for example, when the web.config file is modified and saved). In addition, all requests to this web application seem to use the same instance of the role provider.

So my question is: when does asp.net instantiate role providers? And what is their lifespan? When does asp.net create new instances? And is there a way to get asp.net to update the current provider instance by discarding the old instance and creating a new one?

+4
source share
1 answer

The ASP.NET design assumes that providers are stateless. Therefore, you must design your provider in such a way that you do not need to know when it will be created and when it will die. Basically, if you really want to do this, you can put the actual logic in another class, that its creation and deletion will be handled by the proxy class that you enter in ASP.NET.

Additionally, ASP.NET does not guarantee when it will create the role provider object. This is something like static constructors. You should only rely on them to exist when they are needed.

+2
source

All Articles