开发者

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

开发者 https://www.devze.com 2022-12-13 05:56 出处:网络
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 en

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号