IHttpHandler IHttpHandlerFactory2.GetHandler(HttpContext context, string requestType, VirtualPath virtualPath, string physicalPath) { BuildResultCompiledType vPathBuildResult = (BuildResultCompiledType)BuildManager.GetVPathBuildResult(context, virtualPath); Util.CheckAssignableType(typeof(IHttpHandler), vPathBuildResult.ResultType); return((IHttpHandler)vPathBuildResult.CreateInstance()); }
private static IHttpHandler GetCompiledPageInstance(VirtualPath virtualPath, string inputFile, HttpContext context) { IHttpHandler handler; if (context != null) { virtualPath = context.Request.FilePathObject.Combine(virtualPath); } object state = null; try { try { if (inputFile != null) { state = HostingEnvironment.AddVirtualPathToFileMapping(virtualPath, inputFile); } BuildResultCompiledType type = (BuildResultCompiledType)BuildManager.GetVPathBuildResult(context, virtualPath, false, true, true, true); handler = (IHttpHandler)HttpRuntime.CreatePublicInstance(type.ResultType); } finally { if (state != null) { HostingEnvironment.ClearVirtualPathToFileMapping(state); } } } catch { throw; } return(handler); }
public static Type GetCompiledType(string inputFile, HttpContext context) { // NOTE: the inputFile parameter should be named virtualPath, but cannot be changed // as it would be a minor breaking change! (VSWhidbey 80997). BuildResultCompiledType result = (BuildResultCompiledType)BuildManager.GetVPathBuildResult( context, VirtualPath.Create(inputFile)); return(result.ResultType); }
internal Type GetReferencedType(VirtualPath virtualPath, bool allowNoCompile) { virtualPath = base.ResolveVirtualPath(virtualPath); if ((base._pageParserFilter != null) && !base._pageParserFilter.AllowVirtualReference(base.CompConfig, virtualPath)) { base.ProcessError(System.Web.SR.GetString("Reference_not_allowed", new object[] { virtualPath })); } BuildResult vPathBuildResult = null; Type baseType = null; try { vPathBuildResult = BuildManager.GetVPathBuildResult(virtualPath); } catch (HttpCompileException exception) { if (exception.VirtualPathDependencies != null) { foreach (string str in exception.VirtualPathDependencies) { base.AddSourceDependency(VirtualPath.Create(str)); } } throw; } catch { if (this.IgnoreParseErrors) { base.AddSourceDependency(virtualPath); } throw; } BuildResultNoCompileTemplateControl control = vPathBuildResult as BuildResultNoCompileTemplateControl; if (control != null) { if (!allowNoCompile) { return(null); } baseType = control.BaseType; } else { if (!(vPathBuildResult is BuildResultCompiledType)) { throw new HttpException(System.Web.SR.GetString("Invalid_typeless_reference", new object[] { "src" })); } BuildResultCompiledType type2 = (BuildResultCompiledType)vPathBuildResult; baseType = type2.ResultType; } base.AddTypeDependency(baseType); base.AddBuildResultDependency(vPathBuildResult); return(baseType); }
/* * Compile a web handler file into a Type. Result is cached. */ /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> protected Type GetCompiledTypeFromCache() { // // This method is practically useless, but cannot be removed to avoid a breaking change // BuildResultCompiledType result = (BuildResultCompiledType)BuildManager.GetVPathBuildResult(_virtualPath); return(result.ResultType); }
IHttpHandler IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) { BuildResultCompiledType result = (BuildResultCompiledType)BuildManager.GetVPathBuildResult( context, virtualPath); // Make sure the type has the correct base class (ASURT 123677) Util.CheckAssignableType(typeof(IHttpHandler), result.ResultType); return((IHttpHandler)result.CreateInstance()); }
private static IHttpHandler GetCompiledPageInstance(VirtualPath virtualPath, string inputFile, HttpContext context) { // This is a hacky API that only exists to support web service's // DefaultWsdlHelpGenerator.aspx, which doesn't live under the app root. // To make this work, we add an explicit mapping from the virtual path // to the stream of the passed in file // Make it relative to the current request if necessary if (context != null) { virtualPath = context.Request.FilePathObject.Combine(virtualPath); } object virtualPathToFileMappingState = null; try { try { // If there is a physical path, we need to connect the virtual path to it, so that // the build system will use the right input file for the virtual path. if (inputFile != null) { virtualPathToFileMappingState = HostingEnvironment.AddVirtualPathToFileMapping( virtualPath, inputFile); } BuildResultCompiledType result = (BuildResultCompiledType)BuildManager.GetVPathBuildResult( context, virtualPath, false /*noBuild*/, true /*allowCrossApp*/, true /*allowBuildInPrecompile*/); return((IHttpHandler)HttpRuntime.CreatePublicInstance(result.ResultType)); } finally { if (virtualPathToFileMappingState != null) { HostingEnvironment.ClearVirtualPathToFileMapping(virtualPathToFileMappingState); } } } catch { throw; } }
private Control LoadControl(IWebObjectFactory objectFactory, System.Web.VirtualPath virtualPath, Type t, object[] parameters) { BuildResultCompiledType type = null; BuildResultNoCompileUserControl control = null; PartialCachingAttribute cachingAttribute; if (objectFactory != null) { type = objectFactory as BuildResultCompiledType; if (type != null) { t = type.ResultType; Util.CheckAssignableType(typeof(UserControl), t); } else { control = (BuildResultNoCompileUserControl)objectFactory; } } else if (t != null) { Util.CheckAssignableType(typeof(Control), t); } if (t != null) { cachingAttribute = (PartialCachingAttribute)TypeDescriptor.GetAttributes(t)[typeof(PartialCachingAttribute)]; } else { cachingAttribute = control.CachingAttribute; } if (cachingAttribute == null) { Control control2; if (objectFactory != null) { control2 = (Control)objectFactory.CreateInstance(); } else { control2 = (Control)HttpRuntime.CreatePublicInstance(t, parameters); } UserControl control3 = control2 as UserControl; if (control3 != null) { if (virtualPath != null) { control3.TemplateControlVirtualPath = virtualPath; } control3.InitializeAsUserControl(this.Page); } return(control2); } HashCodeCombiner combinedHashCode = new HashCodeCombiner(); if (objectFactory != null) { combinedHashCode.AddObject(objectFactory); } else { combinedHashCode.AddObject(t); } if (!cachingAttribute.Shared) { this.AddStackContextToHashCode(combinedHashCode); } string combinedHashString = combinedHashCode.CombinedHashString; return(new PartialCachingControl(objectFactory, t, cachingAttribute, "_" + combinedHashString, parameters)); }
public static Type GetCompiledType(string inputFile, HttpContext context) { BuildResultCompiledType vPathBuildResult = (BuildResultCompiledType)BuildManager.GetVPathBuildResult(context, VirtualPath.Create(inputFile)); return(vPathBuildResult.ResultType); }
private Control LoadControl(IWebObjectFactory objectFactory, VirtualPath virtualPath, Type t, object[] parameters) { // Make sure we get an object factory or a type, but not both Debug.Assert((objectFactory == null) != (t == null)); BuildResultCompiledType compiledUCResult = null; BuildResultNoCompileUserControl noCompileUCResult = null; if (objectFactory != null) { // It can be a compiled or no-compile user control compiledUCResult = objectFactory as BuildResultCompiledType; if (compiledUCResult != null) { t = compiledUCResult.ResultType; Debug.Assert(t != null); // Make sure it's a user control (VSWhidbey 428718) Util.CheckAssignableType(typeof(UserControl), t); } else { noCompileUCResult = (BuildResultNoCompileUserControl)objectFactory; Debug.Assert(noCompileUCResult != null); } } else { // Make sure the type has the correct base class (ASURT 123677) if (t != null) { Util.CheckAssignableType(typeof(Control), t); } } PartialCachingAttribute cacheAttrib; // Check if the user control has a PartialCachingAttribute attribute if (t != null) { cacheAttrib = (PartialCachingAttribute) TypeDescriptor.GetAttributes(t)[typeof(PartialCachingAttribute)]; } else { cacheAttrib = noCompileUCResult.CachingAttribute; } if (cacheAttrib == null) { // The control is not cached. Just create it. Control c; if (objectFactory != null) { c = (Control)objectFactory.CreateInstance(); } else { c = (Control)HttpRuntime.CreatePublicInstance(t, parameters); } // If it's a user control, do some extra initialization UserControl uc = c as UserControl; if (uc != null) { Debug.Assert(virtualPath != null); if (virtualPath != null) { uc.TemplateControlVirtualPath = virtualPath; } uc.InitializeAsUserControl(Page); } return(c); } HashCodeCombiner combinedHashCode = new HashCodeCombiner(); // Start by adding the type or object factory of the user control to the hash. // This guarantees that two unrelated user controls don't share the same cached data. if (objectFactory != null) { combinedHashCode.AddObject(objectFactory); } else { combinedHashCode.AddObject(t); } // If it's not shared, add some stack frames to the hash if (!cacheAttrib.Shared) { AddStackContextToHashCode(combinedHashCode); } string cacheKey = combinedHashCode.CombinedHashString; // Wrap it to allow it to be cached return(new PartialCachingControl(objectFactory, t, cacheAttrib, "_" + cacheKey, parameters)); }
protected Type GetCompiledTypeFromCache() { BuildResultCompiledType vPathBuildResult = (BuildResultCompiledType)BuildManager.GetVPathBuildResult(this._virtualPath); return(vPathBuildResult.ResultType); }
internal Type GetReferencedType(VirtualPath virtualPath, bool allowNoCompile) { virtualPath = ResolveVirtualPath(virtualPath); // If we have a page parser filter, make sure the reference is allowed if (_pageParserFilter != null && !_pageParserFilter.AllowVirtualReference(CompConfig, virtualPath)) { ProcessError(SR.GetString(SR.Reference_not_allowed, virtualPath)); } BuildResult result = null; Type t = null; try { result = BuildManager.GetVPathBuildResult(virtualPath); } catch (HttpCompileException e) { // Add the path depdencies properly so we know when // to invalidate the cached result. if (e.VirtualPathDependencies != null) { foreach (string vPath in e.VirtualPathDependencies) { AddSourceDependency(VirtualPath.Create(vPath)); } } throw; } catch { // Add the virtualPath to the dependency so that // we know when to check again. This could happen if the // virtualPath points to a file not created yet. // This only affects designtime code path since we do want to return // partial result even if there is an error, and that result is // cached. VSWhidbey 372585 if (IgnoreParseErrors) { AddSourceDependency(virtualPath); } throw; } // Is it a no-compile page/uc BuildResultNoCompileTemplateControl noCompileResult = result as BuildResultNoCompileTemplateControl; if (noCompileResult != null) { // If no-compile is not acceptable, return null if (!allowNoCompile) { return(null); } // In the no-compile case, use the base type, since we don't compile a type t = noCompileResult.BaseType; } else if (result is BuildResultCompiledType) { BuildResultCompiledType compiledResult = (BuildResultCompiledType)result; Debug.Assert(compiledResult != null); t = compiledResult.ResultType; } else { throw new HttpException(SR.GetString(SR.Invalid_typeless_reference, _sourceString)); } Debug.Assert(t != null); // Add a dependency on the Type AddTypeDependency(t); // Add a dependency on the BuildResult AddBuildResultDependency(result); return(t); }