|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Net;
using System.Web;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Web.Security;
using Signum.Utilities;
using System.Web.Routing;
using Signum.Engine.Exceptions;
using Signum.Engine.Linq;
using Signum.Engine;
namespace Signum.Web
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public sealed class ExecutionContextAttribute : ActionFilterAttribute
{
public static Func<ActionExecutingContext, ExecutionContext> SetExecutionContext = a=> ExecutionContext.UserInterface;
public ExecutionContextAttribute()
{
}
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if(SetExecutionContext != null)
{
ExecutionContext context = SetExecutionContext(filterContext);
filterContext.RequestContext.HttpContext.Items[typeof(ExecutionContext)] = ExecutionContext.Scope(context);
}
}
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
if (SetExecutionContext != null)
{
var oldContext = ExecutionContext.Current;
IDisposable scope = (IDisposable)filterContext.RequestContext.HttpContext.Items[typeof(ExecutionContext)];
if (scope != null)
{
scope.Dispose();
filterContext.RequestContext.HttpContext.Items.Remove(typeof(ExecutionContext));
}
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I'm Computer Scientist, one of the founders of Signum Software, and the lead developer behind Signum Framework.
www.signumframework.com
I love programming in C#, Linq, Compilers, Algorithms, Functional Programming, Computer Graphics, Maths...