diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/Security/AuthorizeAttributeAclModule.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/Security/AuthorizeAttributeAclModule.cs index a3bd4a89..f0579d23 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/Security/AuthorizeAttributeAclModule.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/Security/AuthorizeAttributeAclModule.cs @@ -112,10 +112,16 @@ protected virtual bool VerifyController(ISiteMapNode node, RouteData routes, Typ var controllerContext = this.CreateControllerContext(node, routes, controllerType, controllerFactory, out factoryBuiltController); try { + // Fixes #271 - set controller's ControllerContext property for MVC + controllerContext.Controller.ControllerContext = controllerContext; + return this.VerifyControllerAttributes(node, controllerType, controllerContext); } finally { + // Release the circular reference between Controller-ControllerContext, so it can be GC'd + controllerContext.Controller.ControllerContext = null; + // Release controller if (factoryBuiltController) controllerFactory.ReleaseController(controllerContext.Controller); diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/Web/Mvc/MvcContextFactory.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/Web/Mvc/MvcContextFactory.cs index ad6a3004..e94d8d36 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/Web/Mvc/MvcContextFactory.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/Web/Mvc/MvcContextFactory.cs @@ -47,6 +47,11 @@ public virtual RequestContext CreateRequestContext() public virtual ControllerContext CreateControllerContext(RequestContext requestContext, ControllerBase controller) { + if (requestContext == null) + throw new ArgumentNullException("requestContext"); + if (controller == null) + throw new ArgumentNullException("controller"); + return new ControllerContext(requestContext, controller); } @@ -73,6 +78,11 @@ public virtual IUrlHelper CreateUrlHelper() public virtual AuthorizationContext CreateAuthorizationContext(ControllerContext controllerContext, ActionDescriptor actionDescriptor) { + if (controllerContext == null) + throw new ArgumentNullException("controllerContext"); + if (actionDescriptor == null) + throw new ArgumentNullException("actionDescriptor"); + return new AuthorizationContext(controllerContext, actionDescriptor); }