Monday, September 17, 2012

Conversion between HTTPContext and HTTPContextBase

 
// Getting HttpContext from HttpContextBase:
HttpContext httpContext = httpContextBase.ApplicationInstance.Context;


 
// Getting HttpContextBase from HttpContext:
HttpContextBase httpContextBase = new System.Web.HttpContextWrapper(context);




Wednesday, September 5, 2012

Returning null when implementing IDependencyResolver

We have an MVC4 application that uses the Unity IoC container. Upon startup there were numerous errors like

Activation error occured while trying to get instance of type IControllerFactory, key ""

I found a fix for this in a stackoverflow article: Activation error occured while trying to get instance of type. The article included an implementation of IDependencyResolver that returned null when an object could not be resolved.

I then remembered that that I had used this solution before without really thinking about it.

I found a better explanation in this article ASP.NET MVC 3 Hosting :: Problem in implementing IControllerActivator in ASP.NET MVC 3.