/// <summary> /// Accepts a configuration object from the <see cref="UrlMappingModule"/> /// and initializes the provider. /// </summary> /// <param name="config"> /// the configuration settings typed as a <c>UrlMappingProviderConfiguration</c> object; /// the actual object type may be a subclass of <c>UrlMappingProviderConfiguration</c>. /// </param> void IUrlMappingProvider.Initialize(UrlMappingProviderConfiguration config) { // cast the configuration object provided by the module SqlUrlMappingProviderConfiguration sqlConfig = (config as SqlUrlMappingProviderConfiguration); if (sqlConfig == null) { throw new ProviderException("Invalid SqlUrlMappingProvider configuration. Check the web.config file settings."); } // remember configuration settings _connectionString = sqlConfig.ConnectionStringName; _procName = sqlConfig.ProcName; _tableName = sqlConfig.TableName; _useDependency = sqlConfig.UseDependency; _dependencyName = sqlConfig.DependencyName; _qsBehavior = sqlConfig.IncomingQueryStringBehavior; // if useDependency is set, make sure a dependency name is also if (_useDependency && string.IsNullOrEmpty(_dependencyName)) { throw new ProviderException("Invalid SqlUrlMappingProvider configuration. If 'useDependency' is true, you must supply a 'dependencyName'. Check the web.config file settings."); } // initialize the url mappings RefreshUrlMappingData(); }
/// <summary> /// Accepts a configuration object from the <see cref="UrlMappingModule"/> /// and initializes the provider. /// </summary> /// <param name="config"> /// the configuration settings typed as a <c>UrlMappingProviderConfiguration</c> object; /// the actual object type may be a subclass of <c>UrlMappingProviderConfiguration</c>. /// </param> void IUrlMappingProvider.Initialize(UrlMappingProviderConfiguration config) { // cast the configuration object provided by the module XmlUrlMappingProviderConfiguration xmlConfig = (config as XmlUrlMappingProviderConfiguration); if (xmlConfig == null) { throw new ProviderException("Invalid XmlUrlMappingProvider configuration. Check the web.config file settings."); } // remember configuration settings _urlMappingFile = xmlConfig.UrlMappingFile; _useDependency = xmlConfig.UseDependency; _qsBehavior = xmlConfig.IncomingQueryStringBehavior; // initialize the url mappings RefreshUrlMappingData(); }
private void Initialize() { // get the configuration section UrlMappingProviderConfiguration config = (UrlMappingProviderConfiguration)ConfigurationManager.GetSection(kMAPPINGMODULE); if (config == null) { throw new ProviderException("The configuration section for the UrlMappingModule is missing from Web.config."); } if (!string.IsNullOrEmpty(config.ProviderTypeString)) { // instantiate a concrete provider given the provider type string through reflection Type t = Type.GetType(config.ProviderTypeString); // if the type couldn't be retrieved, it could be because the user has it defined in APP_CODE; // try the BuildManager if (t == null) { t = BuildManager.GetType(config.ProviderTypeString, false, true); } // if we still have an error, throw the exception if (t == null) { throw new ProviderException("Cannot locate the type '" + config.ProviderTypeString + "' for the UrlMappingModule. Check your web.config settings."); } // attempt to instantiate the provider given its type _provider = (IUrlMappingProvider)Activator.CreateInstance(t); } else { _provider = null; } if (_provider == null) { throw new ProviderException("Invalid provider for UrlMappingModule. This must be a type that implements IUrlMappingProvider. Check your web.config settings, section 'urlMappingModule', attribute 'providerType'"); } // remember other configuration properties _noMatchAction = config.NoMatchAction; _noMatchRedirectPage = config.NoMatchRedirectUrl; _automaticallyUpdateFormAction = config.AutomaticallyUpdateFormAction; _qsBehavior = config.IncomingQueryStringBehavior; _processingEvent = config.UrlProcessingEvent; _authorizeRedirectionUrl = config.AuthorizeRedirectionUrl; _authorizeFailureRedirectUrl = config.AuthorizeFailureRedirectUrl; // test configuration combinations if (_authorizeRedirectionUrl == true && _processingEvent != UrlProcessingEventEnum.AuthorizeRequest) { throw new ConfigurationErrorsException("When the <urlMappingModule> 'authorizeRedirectionUrl' attribute is 'true', the 'processEvent' attribute must be 'AuthorizeEvent'."); } // remember the list of extensions to ignore _ignoreExtensions = config.IgnoreExtensions.Split(new char[] { ' ', ';', ',' }); for (int i = 0; i < _ignoreExtensions.Length; i++) { _ignoreExtensions[i] = _ignoreExtensions[i].Trim().ToLower(); } // allow the provider to initialize itself given the configuration section if (_provider != null) { _provider.Initialize(config); } }