Josh Pearce
Josh Pearce

Reputation: 3455

Will My Dispose Methods Get Called at End of ASP.NET Request

I have a lightweight class I use to keep keep track of who the user is in an ASP.NET MVC web request. It retrieves a dictionary from application cache and reads and modifies some values, and at the end of each method where the cached dictionary is accessed, inserts the dictionary back into cache.

I would like to just be able to modify the dictionary, and have it inserted back into cache at the end of the web request by implementing IDisposable. Will ASP.NET call Dispose on every object that was created in the course of the request, or do I need to handle this manually in the application's end request event.

Upvotes: 3

Views: 482

Answers (1)

Andrew Hare
Andrew Hare

Reputation: 351616

No, ASP.NET will not call the Dispose method on any instance. You will need to handle this either with a using statement or by manually calling Dispose on the instance.

Upvotes: 4

Related Questions