protected override void InitializeParameters()
        {
            WebPageBase razorPage = null;

            try
            {
                using (BuildManagerHelper.DisableUrlMetadataCachingScope())
                {
                    razorPage = WebPage.CreateInstanceFromVirtualPath(VirtualPath);
                }

                var razorFunction = razorPage as RazorFunction;
                if (razorFunction == null)
                {
                    throw new InvalidOperationException($"Failed to initialize function from cache. Path: '{VirtualPath}'");
                }

                Parameters = FunctionBasedFunctionProviderHelper.GetParameters(razorFunction, typeof(RazorFunction), VirtualPath);
                PreventFunctionOutputCaching = razorFunction.PreventFunctionOutputCaching;
            }
            finally
            {
                (razorPage as IDisposable)?.Dispose();
            }
        }
예제 #2
0
        public static MasterPage CompileMasterPage(string virtualPath)
        {
            // Calling: object virtualPathObj = new System.Web.VirtualPath(virtualPath);
            Assembly asmSystemWeb           = typeof(HttpContext).Assembly;
            Type     tVirtualType           = asmSystemWeb.GetType("System.Web.VirtualPath");
            var      virtualTypeConstructor = tVirtualType.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null,
                                                                          new[] { typeof(string) }, null);
            object virtualPathObj = virtualTypeConstructor.Invoke(new object[] { virtualPath });

            // Calling: return System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(null, virtualPathObj, false, false, false)


            IWebObjectFactory factory;

            using (BuildManagerHelper.DisableUrlMetadataCachingScope())
            {
                factory = typeof(BuildManager)
                          .GetMethod("GetVPathBuildResultWithNoAssert",
                                     BindingFlags.NonPublic | BindingFlags.Static,
                                     null,
                                     CallingConventions.Any,
                                     new Type[] { typeof(HttpContext), tVirtualType, typeof(bool), typeof(bool), typeof(bool) },
                                     null)
                          .Invoke(null, new object[] { null, virtualPathObj, false, false, false }) as IWebObjectFactory;
            }

            Verify.IsNotNull(factory, "Failed to compile master page file");

            return(factory.CreateInstance() as MasterPage);
        }
        protected override IFunction InstantiateFunction(string virtualPath, string @namespace, string name)
        {
            WebPageBase razorPage;

            using (BuildManagerHelper.DisableUrlMetadataCachingScope())
            {
                razorPage = WebPage.CreateInstanceFromVirtualPath(virtualPath);
            }

            if (!(razorPage is RazorFunction razorFunction))
            {
                Log.LogWarning(nameof(RazorFunctionProvider),
                               $"Razor page '{virtualPath}' does not inherit from the base class for razor functions '{typeof(RazorFunction).FullName}' and will be ignored");
                return(null);
            }

            try
            {
                var functionParameters = FunctionBasedFunctionProviderHelper.GetParameters(
                    razorFunction, typeof(RazorFunction), virtualPath);

                return(new RazorBasedFunction(@namespace, name, razorFunction.FunctionDescription, functionParameters,
                                              razorFunction.FunctionReturnType, virtualPath, this));
            }
            finally
            {
                razorFunction.Dispose();
            }
        }
예제 #4
0
        static void OnAddinStopping(Addin addin)
        {
            // 删除路由
            object ar;
            var    key = addin.Header.Name + "/" + PrivateAreaRegistrations;

            if (addin.Context.Framework.TryGetProperty(key, out ar))
            {
                var privateAreaReg = ar as JointCode.AddIns.Mvc.System.AreaRegistration;
                if (privateAreaReg != null)
                {
                    AreaRegistrationHelper.UnregisterArea(privateAreaReg);
                }
                else
                {
                    AreaRegistrationHelper.UnregisterArea(addin.Header.Name);
                }
            }
            else
            {
                AreaRegistrationHelper.UnregisterArea(addin.Header.Name);
            }

            // 删除程序集引用
            foreach (var asm in addin.Runtime.LoadedAssemblies)
            {
                BuildManagerHelper.RemoveReferencedAssembly(asm);
            }

            //// 删除私有程序集探测路径
            //var probingPath = AppDomain.CurrentDomain.SetupInformation.PrivateBinPath;
            //probingPath.Replace(args.Addin.File.BaseDirectory + ";", string.Empty);
            //AppDomain.CurrentDomain.SetupInformation.PrivateBinPath = probingPath; }
        }
예제 #5
0
        static void OnAddinStarted(Addin addin)
        {
            //// 添加私有程序集探测路径
            //var probingPath = AppDomain.CurrentDomain.SetupInformation.PrivateBinPath ?? string.Empty;
            //probingPath += args.Addin.File.BaseDirectory + ";";
            //AppDomain.CurrentDomain.SetupInformation.PrivateBinPath = probingPath;

            // 添加路由
            var asms = addin.Runtime.LoadAssemblies();

            JointCode.AddIns.Mvc.System.AreaRegistration areaReg = null; // private AreaRegistration implementations
            foreach (var asm in asms)
            {
                Type[] types;
                if (!JcMvcUtil.TryGetTypes(asm, out types))
                {
                    continue;
                }
                foreach (var type in types)
                {
                    if (!type.IsClass || type.IsAbstract)
                    {
                        continue;
                    }
                    if (!typeof(JointCode.AddIns.Mvc.System.AreaRegistration).IsAssignableFrom(type))
                    {
                        continue;
                    }
                    var ar = Activator.CreateInstance(type) as JointCode.AddIns.Mvc.System.AreaRegistration;
                    if (ar != null && areaReg != null)
                    {
                        throw new ConfigurationException(string.Format("More than one private area registrations has been found in addin [{0}]!", addin.Header.Name));
                    }
                    areaReg = ar;
                    AreaRegistrationHelper.RegisterArea(ar, null);
                }
            }
            if (areaReg != null)
            {
                var key = addin.Header.Name + "/" + PrivateAreaRegistrations;
                if (addin.Context.Framework.ContainsPropertyKey(PrivateAreaRegistrations))
                {
                    throw new ConfigurationException(string.Format(
                                                         "The private area registration key [{0}] for addin [{1}] has been taken, please use another area name and try again!", key, addin.Header.Name));
                }
                addin.Context.Framework.SetProperty(key, areaReg);
            }
            else
            {
                AreaRegistrationHelper.RegisterArea(addin.Header.Name, null); // 添加路由
            }

            // 添加程序集引用
            foreach (var asm in asms)
            {
                BuildManagerHelper.AddReferencedAssembly(asm);
            }
        }
        private void context_AuthorizeRequest(object sender, EventArgs e)
        {
            var         application = (HttpApplication)sender;
            HttpContext context     = application.Context;

            string currentPath = context.Request.Path.ToLowerInvariant();

            if (_adminRootPath == null || !currentPath.StartsWith(_adminRootPath))
            {
                return;
            }

            if (!_allowC1ConsoleRequests)
            {
                context.Response.StatusCode  = 403;
                context.Response.ContentType = "text/html";
                string iePadding = new String('!', 512);
                context.Response.Write(string.Format(c1ConsoleRequestsNotAllowedHtmlTemplate, iePadding));
                context.Response.End();
                return;
            }

            var url = context.Request.Url;

            // https check
            if (_forceHttps && url.Scheme != "https")
            {
                if (!AlwaysAllowUnsecured(url.LocalPath) && !UserOptedOutOfHttps(context))
                {
                    context.Response.Redirect(
                        $"{unsecureRedirectRelativePath}?fallback={_allowFallbackToHttp.ToString().ToLower()}&httpsport={_customHttpsPortNumber}");
                }
            }

            // access check
            if (currentPath.Length > _adminRootPath.Length && !UserValidationFacade.IsLoggedIn() &&
                !_allAllowedPaths.Any(p => currentPath.StartsWith(p, StringComparison.OrdinalIgnoreCase)))
            {
                if (currentPath.StartsWith(_servicesPath))
                {
                    context.Response.StatusCode = 403;
                    context.Response.End();
                    return;
                }

                Log.LogWarning("Authorization", "DENIED {0} access to {1}", context.Request.UserHostAddress, currentPath);
                string redirectUrl = $"{_loginPagePath}?ReturnUrl={HttpUtility.UrlEncode(url.PathAndQuery, Encoding.UTF8)}";
                context.Response.Redirect(redirectUrl, true);
                return;
            }

            // On authenticated request make sure these resources gets compiled / launched.
            if (IsConsoleOnline)
            {
                BrowserRender.EnsureReadiness();
                BuildManagerHelper.InitializeControlPreLoading();
            }
        }
        public static UserControl CompileFile(string virtualPath)
        {
            var page = new Page();

            using (BuildManagerHelper.DisableUrlMetadataCachingScope())
            {
                return(page.LoadControl(virtualPath) as UserControl);
            }
        }
        public TemplatedMultiContentXhtmlEditorUiControlFactory(TemplatedMultiContentXhtmlEditorUiControlFactoryData data)
        {
            _data = data;

            if (_data.CacheCompiledUserControlType)
            {
                _cachedUserControlType = BuildManagerHelper.GetCompiledType(_data.UserControlVirtualPath);
            }
        }
        public IUiControl CreateControl()
        {
            Type userControlType = _cachedUserControlType;

            if (userControlType == null && System.Web.HttpContext.Current != null)
            {
                userControlType = BuildManagerHelper.GetCompiledType(_data.UserControlVirtualPath);
            }

            TemplatedMultiContentXhtmlEditorUiControl control = new TemplatedMultiContentXhtmlEditorUiControl(userControlType);

            control.ClassConfigurationName = _data.ClassConfigurationName;

            return(control);
        }
예제 #10
0
        protected override void InitializeParameters()
        {
            WebPageBase razorPage;

            using (BuildManagerHelper.DisableUrlMetadataCachingScope())
            {
                razorPage = WebPage.CreateInstanceFromVirtualPath(VirtualPath);
            }

            if (!(razorPage is RazorFunction))
            {
                throw new InvalidOperationException("Failed to initialize function from cache. Path: '{0}'".FormatWith(VirtualPath));
            }

            Parameters = FunctionBasedFunctionProviderHelper.GetParameters(razorPage as RazorFunction, typeof(RazorFunction), VirtualPath);
        }