Skip to content

Commit

Permalink
Fixes #271, set controller.ControllerContext property in AuthorizeAtt…
Browse files Browse the repository at this point in the history
…ributeAclModule to the new ControllerContext object, because MVC doesn't handle this automatically. Also added a statement in the finally block to set it back to null when we are done with it because otherwise we would have a circular reference memory leak.
  • Loading branch information
NightOwl888 committed Feb 4, 2014
1 parent 6c2c9a2 commit 5db81e5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down

0 comments on commit 5db81e5

Please sign in to comment.