Monthly Archives: January 2011

Media Streaming MVC Alt Approach

Now that the bulk of the holiday season is over, I started back in on my side projects. Tonight’s goal: remove some of the lifting required of developers to implement resuming downloads.

While playing around with the Controller class I started digging into the OnActionExecuted method. From here I had access to the Request and Response objects. In essence, I could unify my 2-prong approach (ActionFilter to scan the request and ActionResult to write the response) in one step and eliminate the need for the developer to do anything at all (except change their code to inherit from ResumingController rather than Controller).

What I’m doing is checking for the 3 ActionResult types that are used when a Controller returns a File() result. I take the values I need and replace the object with my custom result.

The upside: controller code stays the same.

The downside: it feels a little dirty to me. I’m explicitly casting and checking the FilterContext.Result type and replacing it with an equivalent. While it works I’m not sure it passes the smell test.

Continue reading