private static void Initialize()
        {
            HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Low, SR.Feature_not_supported_at_this_level);

            if (_initialized)
            {
                return;
            }

            lock (_initializationLock) {
                if (_initialized)
                {
                    return;
                }

                WebPartsSection         webPartsSection = RuntimeConfig.GetAppConfig().WebParts;
                WebPartsPersonalization personalization = webPartsSection.Personalization;

                Debug.Assert(_providers == null);
                _providers = new PersonalizationProviderCollection();

                ProvidersHelper.InstantiateProviders(personalization.Providers, _providers, typeof(PersonalizationProvider));
                _providers.SetReadOnly();
                _provider = _providers[personalization.DefaultProvider];
                if (_provider == null)
                {
                    throw new ConfigurationErrorsException(
                              SR.GetString(SR.Config_provider_must_exist, personalization.DefaultProvider),
                              personalization.ElementInformation.Properties["defaultProvider"].Source,
                              personalization.ElementInformation.Properties["defaultProvider"].LineNumber);
                }

                _initialized = true;
            }
        }
 public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
 {
     HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Medium, "API_not_supported_at_this_level");
     SecUtility.CheckParameter(ref roleName, true, true, true, 0, "roleName");
     this.InitApp();
     if (throwOnPopulatedRole)
     {
         string[] usersInRole;
         try
         {
             usersInRole = this.GetUsersInRole(roleName);
         }
         catch
         {
             return(false);
         }
         if (usersInRole.Length != 0)
         {
             throw new ProviderException(System.Web.SR.GetString("Role_is_not_empty"));
         }
     }
     object[] args = new object[] { roleName, null };
     this.CallMethod((this._ObjAzScope != null) ? this._ObjAzScope : this._ObjAzApplication, "DeleteRole", args);
     args[0] = 0;
     args[1] = null;
     this.CallMethod((this._ObjAzScope != null) ? this._ObjAzScope : this._ObjAzApplication, "Submit", args);
     return(true);
 }
        public override void CreateRole(string roleName)
        {
            HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Medium, "API_not_supported_at_this_level");
            SecUtility.CheckParameter(ref roleName, true, true, true, 0, "roleName");
            this.InitApp();
            object[] args           = new object[] { roleName, null };
            object   objectToCallOn = this.CallMethod((this._ObjAzScope != null) ? this._ObjAzScope : this._ObjAzApplication, "CreateRole", args);

            args[0] = 0;
            args[1] = null;
            try
            {
                try
                {
                    this.CallMethod(objectToCallOn, "Submit", args);
                }
                finally
                {
                    Marshal.FinalReleaseComObject(objectToCallOn);
                }
            }
            catch
            {
                throw;
            }
        }
コード例 #4
0
 public static ProfileBase Create(string username, bool isAuthenticated)
 {
     if (!ProfileManager.Enabled)
     {
         throw new ProviderException(System.Web.SR.GetString("Profile_not_enabled"));
     }
     InitializeStatic();
     if (s_SingletonInstance != null)
     {
         return(s_SingletonInstance);
     }
     if (s_Properties.Count == 0)
     {
         lock (s_InitializeLock)
         {
             if (s_SingletonInstance == null)
             {
                 s_SingletonInstance = new DefaultProfile();
             }
             return(s_SingletonInstance);
         }
     }
     HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Low, "Feature_not_supported_at_this_level");
     return(CreateMyInstance(username, isAuthenticated));
 }
コード例 #5
0
        //////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////

        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Medium, SR.API_not_supported_at_this_level);
            SecUtility.CheckParameter(ref roleName, true, true, true, 0, "roleName");
            InitApp();
            if (throwOnPopulatedRole)
            {
                string[] users;
                try
                {
                    users = GetUsersInRole(roleName);
                }
                catch
                {
                    return(false);
                }

                if (users.Length != 0)
                {
                    throw new ProviderException(SR.GetString(SR.Role_is_not_empty));
                }
            }

            object[] args = new object[2];

            args[0] = roleName;
            args[1] = null;
            CallMethod(_ObjAzScope != null ? _ObjAzScope : _ObjAzApplication, "DeleteRole", args);

            args[0] = 0;
            args[1] = null;
            CallMethod(_ObjAzScope != null ? _ObjAzScope : _ObjAzApplication, "Submit", args);

            return(true);
        }
コード例 #6
0
        //////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////

        public override void CreateRole(string roleName)
        {
            HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Medium, SR.API_not_supported_at_this_level);
            SecUtility.CheckParameter(ref roleName, true, true, true, 0, "roleName");
            InitApp();
            object[] args = new object[2];
            args[0] = roleName;
            args[1] = null;
            object role = CallMethod(_ObjAzScope != null ? _ObjAzScope : _ObjAzApplication, "CreateRole", args);

            args[0] = 0;
            args[1] = null;

            try {
                try {
                    CallMethod(role, "Submit", args);
                } finally {
                    //
                    // Release the handle to the underlying object
                    //

                    Marshal.FinalReleaseComObject(role);
                }
            } catch {
                throw;
            }
        }
コード例 #7
0
        public override string [] GetRolesForUser(string username)
        {
            HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Low, SR.API_not_supported_at_this_level);
            if (username == null)
            {
                throw new ArgumentNullException("username");
            }
            username = username.Trim();
            IntPtr token = GetCurrentTokenAndCheckName(username);

            if (username.Length < 1)
            {
                return(new string[0]);
            }
            StringBuilder allRoles = new StringBuilder(1024);
            StringBuilder error    = new StringBuilder(1024);

            int status = UnsafeNativeMethods.GetGroupsForUser(token, allRoles, 1024, error, 1024);

            if (status < 0)
            {
                allRoles = new StringBuilder(-status);
                status   = UnsafeNativeMethods.GetGroupsForUser(token, allRoles, -status, error, 1024);
            }
            if (status <= 0)
            {
                throw new ProviderException(SR.GetString(SR.API_failed_due_to_error, error.ToString()));
            }
            string [] roles = allRoles.ToString().Split('\t');
            return(AddLocalGroupsWithoutDomainNames(roles));
        }
コード例 #8
0
        public override string[] GetRolesForUser(string username)
        {
            HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Low, "API_not_supported_at_this_level");
            if (username == null)
            {
                throw new ArgumentNullException("username");
            }
            username = username.Trim();
            IntPtr currentTokenAndCheckName = this.GetCurrentTokenAndCheckName(username);

            if (username.Length < 1)
            {
                return(new string[0]);
            }
            StringBuilder allGroups = new StringBuilder(0x400);
            StringBuilder error     = new StringBuilder(0x400);
            int           num       = System.Web.UnsafeNativeMethods.GetGroupsForUser(currentTokenAndCheckName, allGroups, 0x400, error, 0x400);

            if (num < 0)
            {
                allGroups = new StringBuilder(-num);
                num       = System.Web.UnsafeNativeMethods.GetGroupsForUser(currentTokenAndCheckName, allGroups, -num, error, 0x400);
            }
            if (num <= 0)
            {
                throw new ProviderException(System.Web.SR.GetString("API_failed_due_to_error", new object[] { error.ToString() }));
            }
            return(AddLocalGroupsWithoutDomainNames(allGroups.ToString().Split(new char[] { '\t' })));
        }
コード例 #9
0
        //////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////

        public override void RemoveUsersFromRoles(string[] userNames, string[] roleNames)
        {
            HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Medium, SR.API_not_supported_at_this_level);
            SecUtility.CheckArrayParameter(ref roleNames,
                                           true,
                                           true,
                                           true,
                                           0,
                                           "roleNames");

            SecUtility.CheckArrayParameter(ref userNames,
                                           true,
                                           true,
                                           true,
                                           0,
                                           "userNames");

            int index = 0;

            object[] args  = new object[2];
            object[] roles = new object[roleNames.Length];

            foreach (string rolename in roleNames)
            {
                roles[index++] = GetRole(rolename);
            }

            try {
                try {
                    foreach (object role in roles)
                    {
                        foreach (string username in userNames)
                        {
                            args[0] = username;
                            args[1] = null;
                            CallMethod(role, "DeleteMemberName", args);
                        }
                    }

                    foreach (object role in roles)
                    {
                        args[0] = 0;
                        args[1] = null;
                        CallMethod(role, "Submit", args);
                    }
                } finally {
                    foreach (object role in roles)
                    {
                        Marshal.FinalReleaseComObject(role);
                    }
                }
            } catch {
                throw;
            }
        }
コード例 #10
0
        public static void InvokeTransacted(TransactedCallback callback, TransactionOption mode, ref bool transactionAborted)
        {
            HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Medium, "Transaction_not_supported_in_low_trust");
            bool flag = false;

            if ((Environment.OSVersion.Platform != PlatformID.Win32NT) || (Environment.OSVersion.Version.Major <= 4))
            {
                throw new PlatformNotSupportedException(System.Web.SR.GetString("RequiresNT"));
            }
            if (mode == TransactionOption.Disabled)
            {
                flag = true;
            }
            if (flag)
            {
                callback();
                transactionAborted = false;
            }
            else
            {
                int num;
                TransactedInvocation   invocation = new TransactedInvocation(callback);
                TransactedExecCallback callback2  = new TransactedExecCallback(invocation.ExecuteTransactedCode);
                PerfCounters.IncrementCounter(AppPerfCounter.TRANSACTIONS_PENDING);
                try
                {
                    num = UnsafeNativeMethods.TransactManagedCallback(callback2, (int)mode);
                }
                finally
                {
                    PerfCounters.DecrementCounter(AppPerfCounter.TRANSACTIONS_PENDING);
                }
                if (invocation.Error != null)
                {
                    throw new HttpException(null, invocation.Error);
                }
                PerfCounters.IncrementCounter(AppPerfCounter.TRANSACTIONS_TOTAL);
                switch (num)
                {
                case 1:
                    PerfCounters.IncrementCounter(AppPerfCounter.TRANSACTIONS_COMMITTED);
                    transactionAborted = false;
                    return;

                case 0:
                    PerfCounters.IncrementCounter(AppPerfCounter.TRANSACTIONS_ABORTED);
                    transactionAborted = true;
                    return;
                }
                throw new HttpException(System.Web.SR.GetString("Cannot_execute_transacted_code"));
            }
        }
コード例 #11
0
 private static void Initialize()
 {
     if (!s_Initialized || !s_InitializedDefaultProvider)
     {
         if (s_InitializeException != null)
         {
             throw s_InitializeException;
         }
         if (HostingEnvironment.IsHosted)
         {
             HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Low, "Feature_not_supported_at_this_level");
         }
         lock (s_lock)
         {
             if (!s_Initialized || !s_InitializedDefaultProvider)
             {
                 if (s_InitializeException != null)
                 {
                     throw s_InitializeException;
                 }
                 bool initializeGeneralSettings = !s_Initialized;
                 bool initializeDefaultProvider = !s_InitializedDefaultProvider && (!HostingEnvironment.IsHosted || (BuildManager.PreStartInitStage == PreStartInitStage.AfterPreStartInit));
                 if (initializeDefaultProvider || initializeGeneralSettings)
                 {
                     bool flag3;
                     bool flag4 = false;
                     try
                     {
                         RuntimeConfig     appConfig  = RuntimeConfig.GetAppConfig();
                         MembershipSection membership = appConfig.Membership;
                         flag3 = InitializeSettings(initializeGeneralSettings, appConfig, membership);
                         flag4 = InitializeDefaultProvider(initializeDefaultProvider, membership);
                     }
                     catch (Exception exception)
                     {
                         s_InitializeException = exception;
                         throw;
                     }
                     if (flag3)
                     {
                         s_Initialized = true;
                     }
                     if (flag4)
                     {
                         s_InitializedDefaultProvider = true;
                     }
                 }
             }
         }
     }
 }
コード例 #12
0
        public override void Initialize(string name, NameValueCollection configSettings)
        {
            HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Low, "Feature_not_supported_at_this_level");
            if (configSettings == null)
            {
                throw new ArgumentNullException("configSettings");
            }
            if (string.IsNullOrEmpty(name))
            {
                name = "SqlPersonalizationProvider";
            }
            if (string.IsNullOrEmpty(configSettings["description"]))
            {
                configSettings.Remove("description");
                configSettings.Add("description", System.Web.SR.GetString("SqlPersonalizationProvider_Description"));
            }
            base.Initialize(name, configSettings);
            this._SchemaVersionCheck = 0;
            this._applicationName    = configSettings["applicationName"];
            if (this._applicationName != null)
            {
                configSettings.Remove("applicationName");
                if (this._applicationName.Length > 0x100)
                {
                    object[] args = new object[] { 0x100.ToString(CultureInfo.CurrentCulture) };
                    throw new ProviderException(System.Web.SR.GetString("PersonalizationProvider_ApplicationNameExceedMaxLength", args));
                }
            }
            string str = configSettings["connectionStringName"];

            if (string.IsNullOrEmpty(str))
            {
                throw new ProviderException(System.Web.SR.GetString("PersonalizationProvider_NoConnection"));
            }
            configSettings.Remove("connectionStringName");
            string str2 = SqlConnectionHelper.GetConnectionString(str, true, true);

            if (string.IsNullOrEmpty(str2))
            {
                throw new ProviderException(System.Web.SR.GetString("PersonalizationProvider_BadConnection", new object[] { str }));
            }
            this._connectionString = str2;
            this._commandTimeout   = SecUtility.GetIntValue(configSettings, "commandTimeout", -1, true, 0);
            configSettings.Remove("commandTimeout");
            if (configSettings.Count > 0)
            {
                string key = configSettings.GetKey(0);
                throw new ProviderException(System.Web.SR.GetString("PersonalizationProvider_UnknownProp", new object[] { key, name }));
            }
        }
コード例 #13
0
ファイル: SQLRoleProvider.cs プロジェクト: dox0/DotNet471RS3
        public override void Initialize(string name, NameValueCollection config)
        {
            HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Low, SR.Feature_not_supported_at_this_level);
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            if (String.IsNullOrEmpty(name))
            {
                name = "SqlRoleProvider";
            }
            if (string.IsNullOrEmpty(config["description"]))
            {
                config.Remove("description");
                config.Add("description", SR.GetString(SR.RoleSqlProvider_description));
            }
            base.Initialize(name, config);

            _SchemaVersionCheck = 0;

            _CommandTimeout = SecUtility.GetIntValue(config, "commandTimeout", 30, true, 0);

            _sqlConnectionString = SecUtility.GetConnectionString(config);

            _AppName = config["applicationName"];
            if (string.IsNullOrEmpty(_AppName))
            {
                _AppName = SecUtility.GetDefaultAppName();
            }

            if (_AppName.Length > 256)
            {
                throw new ProviderException(SR.GetString(SR.Provider_application_name_too_long));
            }

            config.Remove("connectionString");
            config.Remove("connectionStringName");
            config.Remove("applicationName");
            config.Remove("commandTimeout");
            if (config.Count > 0)
            {
                string attribUnrecognized = config.GetKey(0);
                if (!String.IsNullOrEmpty(attribUnrecognized))
                {
                    throw new ProviderException(SR.GetString(SR.Provider_unrecognized_attribute, attribUnrecognized));
                }
            }
        }
        public override void RemoveUsersFromRoles(string[] userNames, string[] roleNames)
        {
            HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Medium, "API_not_supported_at_this_level");
            SecUtility.CheckArrayParameter(ref roleNames, true, true, true, 0, "roleNames");
            SecUtility.CheckArrayParameter(ref userNames, true, true, true, 0, "userNames");
            int num = 0;

            object[] args      = new object[2];
            object[] objArray2 = new object[roleNames.Length];
            foreach (string str in roleNames)
            {
                objArray2[num++] = this.GetRole(str);
            }
            try
            {
                try
                {
                    foreach (object obj2 in objArray2)
                    {
                        foreach (string str2 in userNames)
                        {
                            args[0] = str2;
                            args[1] = null;
                            this.CallMethod(obj2, "DeleteMemberName", args);
                        }
                    }
                    foreach (object obj3 in objArray2)
                    {
                        args[0] = 0;
                        args[1] = null;
                        this.CallMethod(obj3, "Submit", args);
                    }
                }
                finally
                {
                    foreach (object obj4 in objArray2)
                    {
                        Marshal.FinalReleaseComObject(obj4);
                    }
                }
            }
            catch
            {
                throw;
            }
        }
コード例 #15
0
 public override void Initialize(string name, NameValueCollection config)
 {
     HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Low, "Feature_not_supported_at_this_level");
     if (config == null)
     {
         throw new ArgumentNullException("config");
     }
     if ((name == null) || (name.Length < 1))
     {
         name = "SqlProfileProvider";
     }
     if (string.IsNullOrEmpty(config["description"]))
     {
         config.Remove("description");
         config.Add("description", System.Web.SR.GetString("ProfileSqlProvider_description"));
     }
     base.Initialize(name, config);
     this._SchemaVersionCheck  = 0;
     this._sqlConnectionString = SecUtility.GetConnectionString(config);
     this._AppName             = config["applicationName"];
     if (string.IsNullOrEmpty(this._AppName))
     {
         this._AppName = SecUtility.GetDefaultAppName();
     }
     if (this._AppName.Length > 0x100)
     {
         throw new ProviderException(System.Web.SR.GetString("Provider_application_name_too_long"));
     }
     this._CommandTimeout = SecUtility.GetIntValue(config, "commandTimeout", 30, true, 0);
     config.Remove("commandTimeout");
     config.Remove("connectionStringName");
     config.Remove("connectionString");
     config.Remove("applicationName");
     if (config.Count > 0)
     {
         string key = config.GetKey(0);
         if (!string.IsNullOrEmpty(key))
         {
             throw new ProviderException(System.Web.SR.GetString("Provider_unrecognized_attribute", new object[] { key }));
         }
     }
 }
        public override void Initialize(string name, NameValueCollection config)
        {
            HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Low, "Feature_not_supported_at_this_level");
            if (string.IsNullOrEmpty(name))
            {
                name = "AuthorizationStoreRoleProvider";
            }
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            if (string.IsNullOrEmpty(config["description"]))
            {
                config.Remove("description");
                config.Add("description", System.Web.SR.GetString("RoleAuthStoreProvider_description"));
            }
            base.Initialize(name, config);
            this._CacheRefreshInterval = SecUtility.GetIntValue(config, "cacheRefreshInterval", 60, false, 0);
            this._ScopeName            = config["scopeName"];
            if ((this._ScopeName != null) && (this._ScopeName.Length == 0))
            {
                this._ScopeName = null;
            }
            this._ConnectionString = config["connectionStringName"];
            if ((this._ConnectionString == null) || (this._ConnectionString.Length < 1))
            {
                throw new ProviderException(System.Web.SR.GetString("Connection_name_not_specified"));
            }
            ConnectionStringSettings settings = RuntimeConfig.GetAppConfig().ConnectionStrings.ConnectionStrings[this._ConnectionString];

            if (settings == null)
            {
                throw new ProviderException(System.Web.SR.GetString("Connection_string_not_found", new object[] { this._ConnectionString }));
            }
            if (string.IsNullOrEmpty(settings.ConnectionString))
            {
                throw new ProviderException(System.Web.SR.GetString("Connection_string_not_found", new object[] { this._ConnectionString }));
            }
            this._ConnectionString = settings.ConnectionString;
            this._AppName          = config["applicationName"];
            if (string.IsNullOrEmpty(this._AppName))
            {
                this._AppName = SecUtility.GetDefaultAppName();
            }
            if (this._AppName.Length > 0x100)
            {
                throw new ProviderException(System.Web.SR.GetString("Provider_application_name_too_long"));
            }
            config.Remove("connectionStringName");
            config.Remove("cacheRefreshInterval");
            config.Remove("applicationName");
            config.Remove("scopeName");
            if (config.Count > 0)
            {
                string key = config.GetKey(0);
                if (!string.IsNullOrEmpty(key))
                {
                    throw new ProviderException(System.Web.SR.GetString("Provider_unrecognized_attribute", new object[] { key }));
                }
            }
        }
コード例 #17
0
        ////////////////////////////////////////////////////////////
        // Public Methods

        //////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////

        public override void Initialize(string name, NameValueCollection config)
        {
            HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Low, SR.Feature_not_supported_at_this_level);
            if (String.IsNullOrEmpty(name))
            {
                name = "AuthorizationStoreRoleProvider";
            }
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            if (string.IsNullOrEmpty(config["description"]))
            {
                config.Remove("description");
                config.Add("description", SR.GetString(SR.RoleAuthStoreProvider_description));
            }
            base.Initialize(name, config);

            _CacheRefreshInterval = SecUtility.GetIntValue(config, "cacheRefreshInterval", 60, false, 0);

            _ScopeName = config["scopeName"];
            if (_ScopeName != null && _ScopeName.Length == 0)
            {
                _ScopeName = null;
            }

            _ConnectionString = config["connectionStringName"];
            if (_ConnectionString == null || _ConnectionString.Length < 1)
            {
                throw new ProviderException(SR.GetString(SR.Connection_name_not_specified));
            }
            ConnectionStringsSection sec1 = null;

            sec1 = RuntimeConfig.GetAppConfig().ConnectionStrings;
            ConnectionStringSettings connObj = sec1.ConnectionStrings[_ConnectionString];

            if (connObj == null)
            {
                throw new ProviderException(SR.GetString(SR.Connection_string_not_found, _ConnectionString));
            }

            if (string.IsNullOrEmpty(connObj.ConnectionString))
            {
                throw new ProviderException(SR.GetString(SR.Connection_string_not_found, _ConnectionString));
            }

            _ConnectionString = connObj.ConnectionString;
            _AppName          = config["applicationName"];
            if (string.IsNullOrEmpty(_AppName))
            {
                _AppName = SecUtility.GetDefaultAppName();
            }

            if (_AppName.Length > 256)
            {
                throw new ProviderException(SR.GetString(SR.Provider_application_name_too_long));
            }

            config.Remove("connectionStringName");
            config.Remove("cacheRefreshInterval");
            config.Remove("applicationName");
            config.Remove("scopeName");
            if (config.Count > 0)
            {
                string attribUnrecognized = config.GetKey(0);
                if (!String.IsNullOrEmpty(attribUnrecognized))
                {
                    throw new ProviderException(SR.GetString(SR.Provider_unrecognized_attribute, attribUnrecognized));
                }
            }
        }
コード例 #18
0
        private static void Initialize()
        {
            if (s_Initialized && s_InitializedDefaultProvider)
            {
                return;
            }
            if (s_InitializeException != null)
            {
                throw s_InitializeException;
            }

            if (HostingEnvironment.IsHosted)
            {
                HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Low, SR.Feature_not_supported_at_this_level);
            }

            lock (s_lock) {
                if (s_Initialized && s_InitializedDefaultProvider)
                {
                    return;
                }
                if (s_InitializeException != null)
                {
                    throw s_InitializeException;
                }

                bool initializeGeneralSettings = !s_Initialized;
                // the default provider can be initialized once the pre start init has happened (i.e. when compilation has begun)
                // or if this is not even a hosted scenario
                bool initializeDefaultProvider = !s_InitializedDefaultProvider &&
                                                 (!HostingEnvironment.IsHosted || BuildManager.PreStartInitStage == PreStartInitStage.AfterPreStartInit);

                if (!initializeDefaultProvider && !initializeGeneralSettings)
                {
                    return;
                }

                bool generalSettingsInitialized;
                bool defaultProviderInitialized = false;
                try {
                    RuntimeConfig     appConfig = RuntimeConfig.GetAppConfig();
                    MembershipSection settings  = appConfig.Membership;
                    generalSettingsInitialized = InitializeSettings(initializeGeneralSettings, appConfig, settings);
                    defaultProviderInitialized = InitializeDefaultProvider(initializeDefaultProvider, settings);
                } catch (Exception e) {
                    s_InitializeException = e;
                    throw;
                }

                // update this state only after the whole method completes to preserve the behavior where
                // the system is uninitialized if any exceptions were thrown.
                if (generalSettingsInitialized)
                {
                    s_Initialized = true;
                }
                if (defaultProviderInitialized)
                {
                    s_InitializedDefaultProvider = true;
                }
            }
        }
コード例 #19
0
ファイル: Roles.cs プロジェクト: dox0/DotNet471RS3
        static private void Initialize()
        {
            if (s_Initialized)
            {
                if (s_InitializeException != null)
                {
                    throw s_InitializeException;
                }
                if (s_InitializedDefaultProvider)
                {
                    return;
                }
            }

            lock (s_lock) {
                if (s_Initialized)
                {
                    if (s_InitializeException != null)
                    {
                        throw s_InitializeException;
                    }
                    if (s_InitializedDefaultProvider)
                    {
                        return;
                    }
                }

                try
                {
                    if (HostingEnvironment.IsHosted)
                    {
                        HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Low, SR.Feature_not_supported_at_this_level);
                    }

                    RoleManagerSection settings = RuntimeConfig.GetAppConfig().RoleManager;
                    //s_InitializeException = new ProviderException(SR.GetString(SR.Roles_feature_not_enabled));
                    if (!s_EnabledSet)
                    {
                        s_Enabled = settings.Enabled;
                    }
                    s_CookieName              = settings.CookieName;
                    s_CacheRolesInCookie      = settings.CacheRolesInCookie;
                    s_CookieTimeout           = (int)settings.CookieTimeout.TotalMinutes;
                    s_CookiePath              = settings.CookiePath;
                    s_CookieRequireSSL        = settings.CookieRequireSSL;
                    s_CookieSlidingExpiration = settings.CookieSlidingExpiration;
                    s_CookieProtection        = settings.CookieProtection;
                    s_Domain = settings.Domain;
                    s_CreatePersistentCookie = settings.CreatePersistentCookie;
                    s_MaxCachedResults       = settings.MaxCachedResults;
                    if (s_Enabled)   // Instantiate providers only if feature is enabled
                    {
                        if (s_MaxCachedResults < 0)
                        {
                            throw new ProviderException(SR.GetString(SR.Value_must_be_non_negative_integer, "maxCachedResults"));
                        }
                        InitializeSettings(settings);
                        InitializeDefaultProvider(settings);
                    }
                } catch (Exception e) {
                    s_InitializeException = e;
                }
                s_Initialized = true;
            }

            if (s_InitializeException != null)
            {
                throw s_InitializeException;
            }
        }
コード例 #20
0
        public override void Initialize(string name, NameValueCollection configSettings)
        {
            HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Low, SR.Feature_not_supported_at_this_level);

            // configSettings cannot be null because there are required settings needed below
            if (configSettings == null)
            {
                throw new ArgumentNullException("configSettings");
            }

            if (String.IsNullOrEmpty(name))
            {
                name = "SqlPersonalizationProvider";
            }

            // description will be set from the base class' Initialize method
            if (string.IsNullOrEmpty(configSettings["description"]))
            {
                configSettings.Remove("description");
                configSettings.Add("description", SR.GetString(SR.SqlPersonalizationProvider_Description));
            }
            base.Initialize(name, configSettings);

            _SchemaVersionCheck = 0;

            // If not available, the default value is set in the get accessor of ApplicationName
            _applicationName = configSettings["applicationName"];
            if (_applicationName != null)
            {
                configSettings.Remove("applicationName");

                if (_applicationName.Length > maxStringLength)
                {
                    throw new ProviderException(SR.GetString(SR.PersonalizationProvider_ApplicationNameExceedMaxLength, maxStringLength.ToString(CultureInfo.CurrentCulture)));
                }
            }

            string connectionStringName = configSettings["connectionStringName"];

            if (String.IsNullOrEmpty(connectionStringName))
            {
                throw new ProviderException(SR.GetString(SR.PersonalizationProvider_NoConnection));
            }
            configSettings.Remove("connectionStringName");

            string connectionString = SqlConnectionHelper.GetConnectionString(connectionStringName, true, true);

            if (String.IsNullOrEmpty(connectionString))
            {
                throw new ProviderException(SR.GetString(SR.PersonalizationProvider_BadConnection, connectionStringName));
            }
            _connectionString = connectionString;

            _commandTimeout = SecUtility.GetIntValue(configSettings, "commandTimeout", -1, true, 0);
            configSettings.Remove("commandTimeout");

            if (configSettings.Count > 0)
            {
                string invalidAttributeName = configSettings.GetKey(0);
                throw new ProviderException(SR.GetString(SR.PersonalizationProvider_UnknownProp, invalidAttributeName, name));
            }
        }
コード例 #21
0
ファイル: Transactions.cs プロジェクト: dox0/DotNet471RS3
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public static void InvokeTransacted(TransactedCallback callback, TransactionOption mode, ref bool transactionAborted)
        {
            // check for hosting permission even if no user code on the stack
            HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Medium, SR.Transaction_not_supported_in_low_trust);

            bool executeWithoutTransaction = false;

#if !FEATURE_PAL // FEATURE_PAL does not enable Transactions
            if (Environment.OSVersion.Platform != PlatformID.Win32NT || Environment.OSVersion.Version.Major <= 4)
            {
                throw new PlatformNotSupportedException(SR.GetString(SR.RequiresNT));
            }
#else // !FEATURE_PAL
            throw new NotImplementedException("ROTORTODO");
#endif // !FEATURE_PAL


            if (mode == TransactionOption.Disabled)
            {
                executeWithoutTransaction = true;
            }

            if (executeWithoutTransaction)
            {
                // bypass the transaction logic
                callback();
                transactionAborted = false;
                return;
            }

            TransactedInvocation   call         = new TransactedInvocation(callback);
            TransactedExecCallback execCallback = new TransactedExecCallback(call.ExecuteTransactedCode);

            PerfCounters.IncrementCounter(AppPerfCounter.TRANSACTIONS_PENDING);

            int rc;
            try {
                rc = UnsafeNativeMethods.TransactManagedCallback(execCallback, (int)mode);
            }
            finally {
                PerfCounters.DecrementCounter(AppPerfCounter.TRANSACTIONS_PENDING);
            }

            // rethrow the expection originally caught in managed code
            if (call.Error != null)
            {
                throw new HttpException(null, call.Error);
            }

            PerfCounters.IncrementCounter(AppPerfCounter.TRANSACTIONS_TOTAL);

            if (rc == 1)
            {
                PerfCounters.IncrementCounter(AppPerfCounter.TRANSACTIONS_COMMITTED);
                transactionAborted = false;
            }
            else if (rc == 0)
            {
                PerfCounters.IncrementCounter(AppPerfCounter.TRANSACTIONS_ABORTED);
                transactionAborted = true;
            }
            else
            {
                throw new HttpException(SR.GetString(SR.Cannot_execute_transacted_code));
            }
        }
コード例 #22
0
        private static void Initialize()
        {
            if (s_Initialized && s_InitializedDefaultProvider)
            {
                return;
            }
            if (s_InitializeException != null)
            {
                throw s_InitializeException;
            }

            if (HostingEnvironment.IsHosted)
            {
                HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Low, SR.Feature_not_supported_at_this_level);
            }

            lock (s_lock) {
                if (s_Initialized && s_InitializedDefaultProvider)
                {
                    return;
                }
                if (s_InitializeException != null)
                {
                    throw s_InitializeException;
                }

                bool initializeGeneralSettings = !s_Initialized;
                // the default provider can be initialized once the pre start init has happened (i.e. when compilation has begun)
                // or if this is not even a hosted scenario
                bool initializeDefaultProvider = !s_InitializedDefaultProvider &&
                                                 (!HostingEnvironment.IsHosted || BuildManager.PreStartInitStage == PreStartInitStage.AfterPreStartInit);

                if (!initializeDefaultProvider && !initializeGeneralSettings)
                {
                    return;
                }

                bool generalSettingsInitialized;
                bool defaultProviderInitialized = false;
                try {
                    RuntimeConfig     appConfig = RuntimeConfig.GetAppConfig();
                    MembershipSection settings  = appConfig.Membership;
                    generalSettingsInitialized = InitializeSettings(initializeGeneralSettings, appConfig, settings);
                    defaultProviderInitialized = InitializeDefaultProvider(initializeDefaultProvider, settings);
                    // VSO #265267 log warning in event log when using clear password and encrypted password in Membership provider
                    // VSO #433626 In order to minimize the behavior change, we are going to read the password format from the config settings only instead of getting from the provider class
                    // Also allow user to opt-out this feature.
                    if (AppSettings.LogMembershipPasswordFormatWarning)
                    {
                        CheckedPasswordFormat(settings);
                    }
                } catch (Exception e) {
                    s_InitializeException = e;
                    throw;
                }

                // update this state only after the whole method completes to preserve the behavior where
                // the system is uninitialized if any exceptions were thrown.
                if (generalSettingsInitialized)
                {
                    s_Initialized = true;
                }
                if (defaultProviderInitialized)
                {
                    s_InitializedDefaultProvider = true;
                }
            }
        }
コード例 #23
0
 private static void Initialize()
 {
     if (s_Initialized)
     {
         if (s_InitializeException != null)
         {
             throw s_InitializeException;
         }
         if (s_InitializedDefaultProvider)
         {
             return;
         }
     }
     lock (s_lock)
     {
         if (s_Initialized)
         {
             if (s_InitializeException != null)
             {
                 throw s_InitializeException;
             }
             if (s_InitializedDefaultProvider)
             {
                 return;
             }
         }
         try
         {
             if (HostingEnvironment.IsHosted)
             {
                 HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Low, "Feature_not_supported_at_this_level");
             }
             RoleManagerSection roleManager = RuntimeConfig.GetAppConfig().RoleManager;
             if (!s_EnabledSet)
             {
                 s_Enabled = roleManager.Enabled;
             }
             s_CookieName              = roleManager.CookieName;
             s_CacheRolesInCookie      = roleManager.CacheRolesInCookie;
             s_CookieTimeout           = (int)roleManager.CookieTimeout.TotalMinutes;
             s_CookiePath              = roleManager.CookiePath;
             s_CookieRequireSSL        = roleManager.CookieRequireSSL;
             s_CookieSlidingExpiration = roleManager.CookieSlidingExpiration;
             s_CookieProtection        = roleManager.CookieProtection;
             s_Domain = roleManager.Domain;
             s_CreatePersistentCookie = roleManager.CreatePersistentCookie;
             s_MaxCachedResults       = roleManager.MaxCachedResults;
             if (s_Enabled)
             {
                 if (s_MaxCachedResults < 0)
                 {
                     throw new ProviderException(System.Web.SR.GetString("Value_must_be_non_negative_integer", new object[] { "maxCachedResults" }));
                 }
                 InitializeSettings(roleManager);
                 InitializeDefaultProvider(roleManager);
             }
         }
         catch (Exception exception)
         {
             s_InitializeException = exception;
         }
         s_Initialized = true;
     }
     if (s_InitializeException != null)
     {
         throw s_InitializeException;
     }
 }