how do i wrap aspnet requests in a using statement?

I was thinking of using the Global.asax.cs

Yes, using some pair of events like HttpApplication.BeginRequest with HttpApplication.EndRequest is the way to do this on ASP.NET pre-Core.

but I would have to span the using { … } statement across all the various events

Yes-ish. What you need to do is split the using logic across those events. E.g., in the BeginRequest event, do the new MemoryStream() and store it in the request context. Then in the EndRequest event, retrieve the MemoryStream from the request context and call Dispose.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top