I wrote an extension class to customize my AuthorizeAttribute for my action methods and I'd like to be able to inject messages into my view when a certain condition is met. I"m using the below code to load up a shared view when a user is not authorized but it's not adding my message to my ViewData collection. Any ideas?
public override void OnAuthorization(AuthorizationContext filterContext)
{
base.OnAuthorization(filterContext);
if (IsNotAuthorized)
{
filterContext.Result = new ViewResult { ViewName = "NotAuthorized" };
filterContext.Controller.ViewData["Message"] = "Go Away";
}
}
I've also tried setting my ViewData["Message"] collection item above the call to change the view with no success.