Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could derive from <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.authorizeattribute.aspx" rel="nofollow"><code>AuthorizeAttribute</code></a> in order to do your custom authorization stuff and implement <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.iactionfilter.aspx" rel="nofollow"><code>IActionFilter</code></a> in order to have access to the <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.iactionfilter.onactionexecuting.aspx" rel="nofollow"><code>OnActionExecuting</code></a> and <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.iactionfilter.onactionexecuted.aspx" rel="nofollow"><code>OnActionExecuted</code></a> events (to do your custom cleanup code):</p> <pre><code>public class AuthorizeAndCleanupAttribute : AuthorizeAttribute, IActionFilter { protected override bool AuthorizeCore(HttpContextBase httpContext) { // TODO: your custom authorization logic return base.AuthorizeCore(httpContext); } public void OnActionExecuted(ActionExecutedContext filterContext) { // TODO: your custom cleanup code } public void OnActionExecuting(ActionExecutingContext filterContext) { } } </code></pre> <p>Obviously you should be aware that neither the <code>OnActionExecuting</code> or the <code>OnActionExecuted</code> events will ever be executed if the authorization fails (a.k.a. the <code>AuthorizeCore</code> method returns false) so make sure you do your cleanup in this method if you are about to return false.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload