4

Closed

NullReference When Redirecting

description

Hi,

I noticed on your blog that some people were having an issue with NullReferenceExceptions being generated when creating a cache key. I am also having this issue and have managed to create a reproducable scenario for this.

My scenario is that when a user goes to a HTTPS version of a page when that page supports standard HTTP I redirect them to the HTTP version. This is handled with an ActionFilter. I have attached a sanitized version of this filter.

If a user goes to the HTTPS version of a page without the donut caching attribute they are successfully redirected to the HTTP version. However, if a DonutOutputCache attribute is decorating the action it generates the following exception:

Category General
Message: An unhandled exception occurred in the HomeController controller class
Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
at DevTrends.MvcDonutCaching.KeyGenerator.GenerateKey(ControllerContext context, CacheSettings cacheSettings)
at DevTrends.MvcDonutCaching.DonutOutputCacheAttribute.OnResultExecuted(ResultExecutedContext filterContext)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func1 continuation)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func
1 continuation)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func1 continuation)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList
1 filters, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName); TraceSource 'w3wp.exe' event


Any input on how to resolve this would appreciated as at present I need to disable donut caching.

Thanks,

Stephen

file attachments

Closed Sep 11, 2013 at 11:30 PM by moonpyk

comments

gustavorubinsky wrote Sep 4, 2012 at 12:02 AM

Hi

I needed to solve this so I made a pull request with a little patch.
Maybe the author can include it on the next version or you can compile by yourself.

This is the fork http://mvcdonutcaching.codeplex.com/SourceControl/network/forks/gustavorubinsky/fixredirects

pstarkov wrote Aug 26, 2013 at 7:52 AM

Hello, please check that issue https://mvcdonutcaching.codeplex.com/workitem/2584

If you have the same that you can use OnAuthorization filtering.