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 ProviderBase InstantiateProvider(ProviderSettings providerSettings, Type providerType) { ProviderBase base2 = null; try { string str = (providerSettings.Type == null) ? null : providerSettings.Type.Trim(); if (string.IsNullOrEmpty(str)) { throw new ArgumentException(System.Web.SR.GetString("Provider_no_type_name")); } Type c = ConfigUtil.GetType(str, "type", providerSettings, true, true); if (!providerType.IsAssignableFrom(c)) { throw new ArgumentException(System.Web.SR.GetString("Provider_must_implement_type", new object[] { providerType.ToString() })); } base2 = (ProviderBase)HttpRuntime.CreatePublicInstance(c); NameValueCollection parameters = providerSettings.Parameters; NameValueCollection config = new NameValueCollection(parameters.Count, StringComparer.Ordinal); foreach (string str2 in parameters) { config[str2] = parameters[str2]; } base2.Initialize(providerSettings.Name, config); } catch (Exception exception) { if (exception is ConfigurationException) { throw; } throw new ConfigurationErrorsException(exception.Message, exception, providerSettings.ElementInformation.Properties["type"].Source, providerSettings.ElementInformation.Properties["type"].LineNumber); } return(base2); }
void InitCustomEvaluator(RuleInfo ruleInfo) { string customEvaluator = ruleInfo._customEvaluator; if (customEvaluator == null || customEvaluator.Trim().Length == 0) { ruleInfo._customEvaluatorType = null; return; } ruleInfo._customEvaluatorType = ConfigUtil.GetType(ruleInfo._customEvaluator, "custom", ruleInfo._customEvaluatorConfig); // Make sure the type support WebBaseEvent HandlerBase.CheckAssignableType(ruleInfo._customEvaluatorConfig.ElementInformation.Properties["custom"].Source, ruleInfo._customEvaluatorConfig.ElementInformation.Properties["custom"].LineNumber, typeof(System.Web.Management.IWebEventCustomEvaluator), ruleInfo._customEvaluatorType); // Create a public instance of the custom evaluator if (_customEvaluatorInstances[ruleInfo._customEvaluatorType] == null) { _customEvaluatorInstances[ruleInfo._customEvaluatorType] = HttpRuntime.CreatePublicInstance(ruleInfo._customEvaluatorType); } }
internal override Control CreateCachedControl() { Control cachedControl; if (_objectFactory != null) { cachedControl = (Control)_objectFactory.CreateInstance(); } else { // Instantiate the control cachedControl = (Control)HttpRuntime.CreatePublicInstance(_createCachedControlType, _args); } // If it's a user control, do some extra initialization UserControl uc = cachedControl as UserControl; if (uc != null) { uc.InitializeAsUserControl(Page); } cachedControl.ID = _ctrlID; return(cachedControl); }
/* * This code is only used in the non-compiled mode. * It is used at design-time and when the user calls Page.ParseControl. */ internal virtual object BuildObject() { Debug.Assert(InDesigner || NonCompiledPage, "Expected to be in designer mode."); // If it has a ConstructorNeedsTagAttribute, it needs a tag name ConstructorNeedsTagAttribute cnta = (ConstructorNeedsTagAttribute) TypeDescriptor.GetAttributes(ControlType)[typeof(ConstructorNeedsTagAttribute)]; Object obj; if (cnta != null && cnta.NeedsTag) { // Create the object, using its ctor that takes the tag name Object[] args = new Object[] { TagName }; obj = HttpRuntime.CreatePublicInstance(_ctrlType, args); } else { // Create the object obj = HttpRuntime.CreatePublicInstance(_ctrlType); } InitObject(obj); return(obj); }
private static HttpEncoder GetCustomEncoderFromConfig() { HttpRuntimeSection httpRuntime = RuntimeConfig.GetAppConfig().HttpRuntime; Type userBaseType = ConfigUtil.GetType(httpRuntime.EncoderType, "encoderType", httpRuntime); ConfigUtil.CheckBaseType(typeof(HttpEncoder), userBaseType, "encoderType", httpRuntime); return((HttpEncoder)HttpRuntime.CreatePublicInstance(userBaseType)); }
private static RequestValidator GetCustomValidatorFromConfig() { HttpRuntimeSection httpRuntime = RuntimeConfig.GetAppConfig().HttpRuntime; Type userBaseType = ConfigUtil.GetType(httpRuntime.RequestValidationType, "requestValidationType", httpRuntime); ConfigUtil.CheckBaseType(typeof(RequestValidator), userBaseType, "requestValidationType", httpRuntime); return((RequestValidator)HttpRuntime.CreatePublicInstance(userBaseType)); }
public virtual void InstantiateIn(Control control) { UserControl uc = (UserControl)HttpRuntime.CreatePublicInstance(_ctrlType); // Make sure that the user control is not used as the binding container, // since we want its *parent* to be the binding container. uc.SetNonBindingContainer(); uc.InitializeAsUserControl(control.Page); control.Controls.Add(uc); }
public object CreateInstance() { if (!this._triedToGetInstObj) { this._instObj = ObjectFactoryCodeDomTreeGenerator.GetFastObjectCreationDelegate(this.ResultType); this._triedToGetInstObj = true; } if (this._instObj == null) { return(HttpRuntime.CreatePublicInstance(this.ResultType)); } return(this._instObj()); }
/// <include file='doc\TemplateControl.uex' path='docs/doc[@for="TemplateControl.LoadControl2"]/*' /> /// <devdoc> /// <para>Obtains a <see cref='System.Web.UI.UserControl'/> object from a control type.</para> /// </devdoc> internal Control LoadControl(Type t) { // Make sure the type has the correct base class (ASURT 123677) Util.CheckAssignableType(typeof(Control), t); // Check if the user control type has a PartialCachingAttribute attribute PartialCachingAttribute cacheAttrib = (PartialCachingAttribute) TypeDescriptor.GetAttributes(t)[typeof(PartialCachingAttribute)]; if (cacheAttrib == null) { // The control is not cached. Just create it. Control c = (Control)HttpRuntime.CreatePublicInstance(t); UserControl uc = c as UserControl; if (uc != null) { uc.InitializeAsUserControl(Page); } return(c); } string cacheKey; if (cacheAttrib.Shared) { // If the caching is shared, use the type of the control as the key cacheKey = t.GetHashCode().ToString(); } else { // Make sure we have reflection permission to use GetMethod below (ASURT 106196) InternalSecurityPermissions.Reflection.Assert(); HashCodeCombiner combinedHashCode = new HashCodeCombiner(); // Get a cache key based on the top two items of the caller's stack. // It's not guaranteed unique, but for all common cases, it will be StackTrace st = new StackTrace(); for (int i = 1; i < 3; i++) { StackFrame f = st.GetFrame(i); combinedHashCode.AddObject(f.GetMethod()); combinedHashCode.AddObject(f.GetNativeOffset()); } cacheKey = combinedHashCode.CombinedHashString; } // Wrap it to allow it to be cached return(new PartialCachingControl(t, cacheAttrib, "_" + cacheKey)); }
private WebEventProvider GetProviderInstance(string providerName) { object obj2 = this._instances[providerName]; if (obj2 == null) { return(null); } ProviderSettings settings = obj2 as ProviderSettings; if (settings != null) { WebEventProvider provider; Type c = BuildManager.GetType(settings.Type, false); if (typeof(IInternalWebEventProvider).IsAssignableFrom(c)) { provider = (WebEventProvider)HttpRuntime.CreateNonPublicInstance(c); } else { provider = (WebEventProvider)HttpRuntime.CreatePublicInstance(c); } ProcessImpersonationContext context = new ProcessImpersonationContext(); try { provider.Initialize(settings.Name, settings.Parameters); } catch (ConfigurationErrorsException) { throw; } catch (ConfigurationException exception) { throw new ConfigurationErrorsException(exception.Message, settings.ElementInformation.Properties["type"].Source, settings.ElementInformation.Properties["type"].LineNumber); } catch { throw; } finally { if (context != null) { ((IDisposable)context).Dispose(); } } this._instances[providerName] = provider; return(provider); } return(obj2 as WebEventProvider); }
private static void EnsureResourceProviderFactory() { if (s_resourceProviderFactory == null) { Type resourceProviderFactoryTypeInternal = null; resourceProviderFactoryTypeInternal = RuntimeConfig.GetAppConfig().Globalization.ResourceProviderFactoryTypeInternal; if (resourceProviderFactoryTypeInternal == null) { s_resourceProviderFactory = new ResXResourceProviderFactory(); } else { s_resourceProviderFactory = (ResourceProviderFactory)HttpRuntime.CreatePublicInstance(resourceProviderFactoryTypeInternal); } } }
private static RequestValidator GetCustomValidatorFromConfig() { // App since this is static per AppDomain RuntimeConfig config = RuntimeConfig.GetAppConfig(); HttpRuntimeSection runtimeSection = config.HttpRuntime; string validatorTypeName = runtimeSection.RequestValidationType; // validate the type Type validatorType = ConfigUtil.GetType(validatorTypeName, "requestValidationType", runtimeSection); ConfigUtil.CheckBaseType(typeof(RequestValidator) /* expectedBaseType */, validatorType, "requestValidationType", runtimeSection); // instantiate RequestValidator validator = (RequestValidator)HttpRuntime.CreatePublicInstance(validatorType); return(validator); }
internal override Control CreateCachedControl() { // Make sure the type has the correct base class (ASURT 123677) Util.CheckAssignableType(typeof(Control), _createCachedControlType); // Instantiate the control _cachedControl = (Control)HttpRuntime.CreatePublicInstance(_createCachedControlType); if (_cachedControl is UserControl) { ((UserControl)_cachedControl).InitializeAsUserControl(Page); } _cachedControl.ID = _ctrlID; return(_cachedControl); }
private static HttpEncoder GetCustomEncoderFromConfig() { // App since this is static per AppDomain RuntimeConfig config = RuntimeConfig.GetAppConfig(); HttpRuntimeSection runtimeSection = config.HttpRuntime; string encoderTypeName = runtimeSection.EncoderType; // validate the type Type encoderType = ConfigUtil.GetType(encoderTypeName, "encoderType", runtimeSection); ConfigUtil.CheckBaseType(typeof(HttpEncoder) /* expectedBaseType */, encoderType, "encoderType", runtimeSection); // instantiate HttpEncoder encoder = (HttpEncoder)HttpRuntime.CreatePublicInstance(encoderType); return(encoder); }
private void InitCustomEvaluator(RuleInfo ruleInfo) { string str = ruleInfo._customEvaluator; if ((str == null) || (str.Trim().Length == 0)) { ruleInfo._customEvaluatorType = null; } else { ruleInfo._customEvaluatorType = ConfigUtil.GetType(ruleInfo._customEvaluator, "custom", ruleInfo._customEvaluatorConfig); System.Web.Configuration.HandlerBase.CheckAssignableType(ruleInfo._customEvaluatorConfig.ElementInformation.Properties["custom"].Source, ruleInfo._customEvaluatorConfig.ElementInformation.Properties["custom"].LineNumber, typeof(IWebEventCustomEvaluator), ruleInfo._customEvaluatorType); if (this._customEvaluatorInstances[ruleInfo._customEvaluatorType] == null) { this._customEvaluatorInstances[ruleInfo._customEvaluatorType] = HttpRuntime.CreatePublicInstance(ruleInfo._customEvaluatorType); } } }
/// <include file='doc\BaseCompiler.uex' path='docs/doc[@for="BaseCompiler.GetCompiledType"]/*' /> /// <devdoc> /// /// </devdoc> protected Type GetCompiledType() { // Instantiate an ICompiler based on the language CodeDomProvider codeProvider = (CodeDomProvider)HttpRuntime.CreatePublicInstance( CompilerInfo.CompilerType); ICodeCompiler compiler = codeProvider.CreateCompiler(); _generator = codeProvider.CreateGenerator(); _stringResourceBuilder = new StringResourceBuilder(); // Build the data tree that needs to be compiled BuildSourceDataTree(); // Create the resource file if needed if (_stringResourceBuilder.HasStrings) { string resFileName = _compilParams.TempFiles.AddExtension("res"); _stringResourceBuilder.CreateResourceFile(resFileName); CompilParams.Win32Resource = resFileName; } // Compile into an assembly CompilerResults results; try { results = codeProvider.CreateCompiler().CompileAssemblyFromDom(_compilParams, _sourceData); } catch (Exception e) { throw new HttpUnhandledException(HttpRuntime.FormatResourceString(SR.CompilationUnhandledException, codeProvider.GetType().FullName), e); } string fullTypeName = _sourceDataNamespace.Name + "." + _sourceDataClass.Name; ThrowIfCompilerErrors(results, codeProvider, _sourceData, null, null); // After the compilation, update the list of assembly dependencies to be what // the assembly actually needs. Parser.AssemblyDependencies = Util.GetReferencedAssembliesHashtable( results.CompiledAssembly); // Get the type from the assembly return(results.CompiledAssembly.GetType(fullTypeName, true /*throwOnFail*/)); }
private ISessionIDManager InitSessionIDManager(SessionStateSection config) { ISessionIDManager manager; string sessionIDManagerType = config.SessionIDManagerType; if (string.IsNullOrEmpty(sessionIDManagerType)) { manager = new SessionIDManager(); this._usingAspnetSessionIdManager = true; } else { Type type = ConfigUtil.GetType(sessionIDManagerType, "sessionIDManagerType", config); ConfigUtil.CheckAssignableType(typeof(ISessionIDManager), type, config, "sessionIDManagerType"); manager = (ISessionIDManager)HttpRuntime.CreatePublicInstance(type); } manager.Initialize(); return(manager); }
private IPartitionResolver InitPartitionResolver(SessionStateSection config) { string partitionResolverType = config.PartitionResolverType; if (string.IsNullOrEmpty(partitionResolverType)) { return(null); } if ((config.Mode != SessionStateMode.StateServer) && (config.Mode != SessionStateMode.SQLServer)) { throw new ConfigurationErrorsException(System.Web.SR.GetString("Cant_use_partition_resolve"), config.ElementInformation.Properties["partitionResolverType"].Source, config.ElementInformation.Properties["partitionResolverType"].LineNumber); } Type type = ConfigUtil.GetType(partitionResolverType, "partitionResolverType", config); ConfigUtil.CheckAssignableType(typeof(IPartitionResolver), type, config, "partitionResolverType"); IPartitionResolver resolver = (IPartitionResolver)HttpRuntime.CreatePublicInstance(type); resolver.Initialize(); return(resolver); }
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; } }
internal override Control CreateCachedControl() { Control control; if (this._objectFactory != null) { control = (Control)this._objectFactory.CreateInstance(); } else { control = (Control)HttpRuntime.CreatePublicInstance(this._createCachedControlType, this._args); } UserControl control2 = control as UserControl; if (control2 != null) { control2.InitializeAsUserControl(this.Page); } control.ID = base._ctrlID; return(control); }
private static void EnsureResourceProviderFactory() { if (s_resourceProviderFactory != null) { return; } Type t = null; GlobalizationSection globConfig = RuntimeConfig.GetAppConfig().Globalization; t = globConfig.ResourceProviderFactoryTypeInternal; // If we got a type from config, use it. Otherwise, use default factory if (t == null) { s_resourceProviderFactory = new ResXResourceProviderFactory(); } else { s_resourceProviderFactory = (ResourceProviderFactory)HttpRuntime.CreatePublicInstance(t); } }
internal static ProviderBase InstantiateProvider(NameValueCollection providerSettings, Type providerType) { ProviderBase provider = null; try { string pnName = GetAndRemoveStringValue(providerSettings, "name"); string pnType = GetAndRemoveStringValue(providerSettings, "type"); if (string.IsNullOrEmpty(pnType)) { throw new ArgumentException(SR.GetString(SR.Provider_no_type_name)); } Type t = ConfigUtil.GetType(pnType, "type", null, null, true, true); if (!providerType.IsAssignableFrom(t)) { throw new ArgumentException(SR.GetString(SR.Provider_must_implement_type, providerType.ToString())); } provider = (ProviderBase)HttpRuntime.CreatePublicInstance(t); // Because providers modify the parameters collection (i.e. delete stuff), pass in a clone of the collection NameValueCollection cloneParams = new NameValueCollection(providerSettings.Count, StringComparer.Ordinal); foreach (string key in providerSettings) { cloneParams[key] = providerSettings[key]; } provider.Initialize(pnName, cloneParams); } catch (Exception e) { if (e is ConfigurationException) { throw; } throw new ConfigurationErrorsException(e.Message, e); } return(provider); }
public static ProviderBase InstantiateProvider(ProviderSettings providerSettings, Type providerType) { ProviderBase provider = null; try { string pnType = (providerSettings.Type == null) ? null : providerSettings.Type.Trim(); if (string.IsNullOrEmpty(pnType)) { throw new ArgumentException(SR.GetString(SR.Provider_no_type_name)); } Type t = ConfigUtil.GetType(pnType, "type", providerSettings, true, true); if (!providerType.IsAssignableFrom(t)) { throw new ArgumentException(SR.GetString(SR.Provider_must_implement_type, providerType.ToString())); } provider = (ProviderBase)HttpRuntime.CreatePublicInstance(t); // Because providers modify the parameters collection (i.e. delete stuff), pass in a clone of the collection NameValueCollection pars = providerSettings.Parameters; NameValueCollection cloneParams = new NameValueCollection(pars.Count, StringComparer.Ordinal); foreach (string key in pars) { cloneParams[key] = pars[key]; } provider.Initialize(providerSettings.Name, cloneParams); } catch (Exception e) { if (e is ConfigurationException) { throw; } throw new ConfigurationErrorsException(e.Message, e, providerSettings.ElementInformation.Properties["type"].Source, providerSettings.ElementInformation.Properties["type"].LineNumber); } return(provider); }
internal object GetCompiledInstance(string virtualPath, string inputFile, HttpContext context) { ParserCacheItem cacheItem = CompileAndGetParserCacheItem(virtualPath, inputFile, context); // Instantiate the object object ob = null; try { if (cacheItem.trivialPageContent != null) { Debug.Assert(cacheItem.type == null); ob = new TrivialPage(cacheItem.trivialPageContent); } else { // impersonate client while executing page ctor (see 89712) // (compilation is done while not impersonating client) context.Impersonation.ReimpersonateIfSuspended(); try { ob = HttpRuntime.CreatePublicInstance(cacheItem.type); } finally { context.Impersonation.StopReimpersonation(); } } } catch (Exception e) { throw new HttpException(HttpRuntime.FormatResourceString( SR.Failed_to_create_page_of_type, cacheItem.type.FullName), e); } return(ob); }
private SourceCompilerCachedEntry CompileAndCache() { BaseCompiler.GenerateCompilerParameters(_compilParams); // Get the set of config assemblies for our context IDictionary configAssemblies = CompilationConfiguration.GetAssembliesFromContext(_context); if (_assemblies == null) { _assemblies = new Hashtable(); } // Add all the assemblies from the config object to the hashtable // This guarantees uniqueness if (configAssemblies != null) { foreach (Assembly asm in configAssemblies.Values) { _assemblies[asm] = null; } } // And the assembly of the application object (global.asax) _assemblies[HttpApplicationFactory.ApplicationType.Assembly] = null; // Now add all the passed in assemblies to the compilParams foreach (Assembly asm in _assemblies.Keys) { _compilParams.ReferencedAssemblies.Add(Util.GetAssemblyCodeBase(asm)); } // Instantiate the Compiler CodeDomProvider codeProvider = (CodeDomProvider)HttpRuntime.CreatePublicInstance(_compilerType); ICodeCompiler compiler = codeProvider.CreateCompiler(); CompilerResults results; // Compile the source file or string into an assembly try { _utcStart = DateTime.UtcNow; // If we have a source file, read it as a string and compile it. This way, // the compiler never needs to read the original file, avoiding permission // issues (see ASURT 112718) if (_sourceString == null) { _sourceString = Util.StringFromFile(_physicalPath, _context); // Put in some context so that the file can be debugged. _linePragma = new CodeLinePragma(_physicalPath, 1); } CodeSnippetCompileUnit snippetCompileUnit = new CodeSnippetCompileUnit(_sourceString); snippetCompileUnit.LinePragma = _linePragma; results = compiler.CompileAssemblyFromDom(_compilParams, snippetCompileUnit); } catch (Exception e) { throw new HttpUnhandledException(HttpRuntime.FormatResourceString(SR.CompilationUnhandledException, codeProvider.GetType().FullName), e); } BaseCompiler.ThrowIfCompilerErrors(results, codeProvider, null, _physicalPath, _sourceString); SourceCompilerCachedEntry scce = new SourceCompilerCachedEntry(); // Load the assembly scce._assembly = results.CompiledAssembly; // If we have a type name, load the type from the assembly if (_typeName != null) { scce._type = scce._assembly.GetType(_typeName); // If the type could not be loaded, delete the assembly and rethrow if (scce._type == null) { PreservedAssemblyEntry.RemoveOutOfDateAssembly(scce._assembly.GetName().Name); // Remember why we failed _typeNotFoundInAssembly = true; throw new HttpException( HttpRuntime.FormatResourceString(SR.Could_not_create_type, _typeName)); } } CacheEntryToDisk(scce); CacheEntryToMemory(scce); return(scce); }
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)); }
WebEventProvider GetProviderInstance(string providerName) { WebEventProvider provider; object o; o = _instances[providerName]; if (o == null) { return(null); } ProviderSettings providerSettings = o as ProviderSettings; if (providerSettings != null) { // If what we got is still a ProviderSettings, it means we haven't created an instance // of it yet. Type type; string typeName = providerSettings.Type; type = BuildManager.GetType(typeName, false); Debug.Assert(type != null, "type != null"); if (typeof(IInternalWebEventProvider).IsAssignableFrom(type)) { provider = (WebEventProvider)HttpRuntime.CreateNonPublicInstance(type); } else { provider = (WebEventProvider)HttpRuntime.CreatePublicInstance(type); } using (new ProcessImpersonationContext()) { try { provider.Initialize(providerSettings.Name, providerSettings.Parameters); } catch (ConfigurationErrorsException) { throw; } catch (ConfigurationException e) { throw new ConfigurationErrorsException(e.Message, providerSettings.ElementInformation.Properties["type"].Source, providerSettings.ElementInformation.Properties["type"].LineNumber); } catch { throw; } } Debug.Trace("ProviderInstances", "Create a provider instance: " + "name=" + providerSettings.Name + ";type=" + typeName); _instances[providerName] = provider; } else { provider = o as WebEventProvider; Debug.Assert(provider != null, "provider != null"); } return(provider); }
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)); }