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(); } }
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(); } }
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); }
public static UserControl CompileFile(string virtualPath) { var page = new Page(); using (BuildManagerHelper.DisableUrlMetadataCachingScope()) { return(page.LoadControl(virtualPath) as UserControl); } }
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); }