예제 #1
0
        public static TargetingContext GetTargetingContext(this System.Web.HttpContextBase httpContext, IEngine engine = null)
        {
            var context = httpContext.Items["N2.TargetingContext"] as TargetingContext;

            if (context == null)
            {
                if (!TargetingRadar.Enabled)
                {
                    return(new TargetingContext(httpContext));
                }

                if (httpContext.Request["targets"] != null && httpContext.GetEngine(engine).SecurityManager.IsEditor(httpContext.User))
                {
                    var targets = httpContext.Request["targets"].Split(',');
                    return(new TargetingContext(httpContext)
                    {
                        TargetedBy = GetRadar(httpContext, engine).Detectors.Where(d => targets.Contains(d.Name)).ToList()
                    });
                }
                else
                {
                    httpContext.Items["N2.TargetingContext"] = context = GetRadar(httpContext, engine).BuildTargetingContext(httpContext);
                }
            }
            return(context);
        }
예제 #2
0
 private static TargetingRadar GetRadar(System.Web.HttpContextBase httpContext, IEngine engine)
 {
     return(httpContext.GetEngine(engine).Resolve <TargetingRadar>());
 }