Esempio n. 1
0
        internal static void CheckArrayParameter(ref string[] param, bool checkForNull, bool checkIfEmpty, bool checkForCommas, int maxSize, string paramName)
        {
            if (param == null)
            {
                throw new ArgumentNullException(paramName);
            }
            if (param.Length < 1)
            {
                throw new ArgumentException(SR.GetString("The array parameter '{0}' should not be empty.", paramName), paramName);
            }
            Hashtable hashtable = new Hashtable(param.Length);

            for (int i = param.Length - 1; i >= 0; i--)
            {
                SecUtility.CheckParameter(ref param[i], checkForNull, checkIfEmpty, checkForCommas, maxSize, paramName + "[ " + i.ToString(CultureInfo.InvariantCulture) + " ]");
                if (hashtable.Contains(param[i]))
                {
                    throw new ArgumentException(SR.GetString("The array '{0}' should not contain duplicate values.", paramName), paramName);
                }
                hashtable.Add(param[i], param[i]);
            }
        }
Esempio n. 2
0
        public override bool IsUserInRole(string username, string roleName)
        {
            SecUtility.CheckParameter(ref roleName, true, true, true, 256, "roleName");
            SecUtility.CheckParameter(ref username, true, false, true, 256, "username");
            if (username.Length < 1)
            {
                return(false);
            }
            bool result;

            try
            {
                SqlConnectionHolder sqlConnectionHolder = null;
                try
                {
                    sqlConnectionHolder = SqlConnectionHelper.GetConnection(this._sqlConnectionString, true);
                    SqlCommand sqlCommand = new SqlCommand("dbo.aspnet_UsersInRoles_IsUserInRole", sqlConnectionHolder.Connection);
                    sqlCommand.CommandType    = CommandType.StoredProcedure;
                    sqlCommand.CommandTimeout = this.CommandTimeout;
                    SqlParameter sqlParameter = new SqlParameter("@ReturnValue", SqlDbType.Int);
                    sqlParameter.Direction = ParameterDirection.ReturnValue;
                    sqlCommand.Parameters.Add(sqlParameter);
                    sqlCommand.Parameters.Add(this.CreateInputParam("@UserName", SqlDbType.NVarChar, username));
                    sqlCommand.Parameters.Add(this.CreateInputParam("@RoleName", SqlDbType.NVarChar, roleName));
                    sqlCommand.ExecuteNonQuery();
                    switch (this.GetReturnValue(sqlCommand))
                    {
                    case 0:
                        result = false;
                        break;

                    case 1:
                        result = true;
                        break;

                    case 2:
                        result = false;
                        break;

                    case 3:
                        result = false;
                        break;

                    default:
                        throw new ProviderException(SR.GetString("Stored procedure call failed."));
                    }
                }
                finally
                {
                    if (sqlConnectionHolder != null)
                    {
                        sqlConnectionHolder.Close();
                        sqlConnectionHolder = null;
                    }
                }
            }
            catch
            {
                throw;
            }
            return(result);
        }
Esempio n. 3
0
        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            SecUtility.CheckParameter(ref roleName, true, true, true, 256, "roleName");
            SecUtility.CheckParameter(ref usernameToMatch, true, true, false, 256, "usernameToMatch");
            string[] result;
            try
            {
                SqlConnectionHolder sqlConnectionHolder = null;
                try
                {
                    sqlConnectionHolder = SqlConnectionHelper.GetConnection(this._sqlConnectionString, true);
                    SqlCommand       sqlCommand       = new SqlCommand("dbo.aspnet_UsersInRoles_FindUsersInRole", sqlConnectionHolder.Connection);
                    SqlDataReader    sqlDataReader    = null;
                    SqlParameter     sqlParameter     = new SqlParameter("@ReturnValue", SqlDbType.Int);
                    StringCollection stringCollection = new StringCollection();
                    sqlCommand.CommandType    = CommandType.StoredProcedure;
                    sqlCommand.CommandTimeout = this.CommandTimeout;
                    sqlParameter.Direction    = ParameterDirection.ReturnValue;
                    sqlCommand.Parameters.Add(sqlParameter);
                    sqlCommand.Parameters.Add(this.CreateInputParam("@RoleName", SqlDbType.NVarChar, roleName));
                    sqlCommand.Parameters.Add(this.CreateInputParam("@UserNameToMatch", SqlDbType.NVarChar, usernameToMatch));
                    try
                    {
                        sqlDataReader = sqlCommand.ExecuteReader(CommandBehavior.SequentialAccess);
                        while (sqlDataReader.Read())
                        {
                            stringCollection.Add(sqlDataReader.GetString(0));
                        }
                    }
                    catch
                    {
                        throw;
                    }
                    finally
                    {
                        if (sqlDataReader != null)
                        {
                            sqlDataReader.Close();
                        }
                    }
                    if (stringCollection.Count < 1)
                    {
                        switch (this.GetReturnValue(sqlCommand))
                        {
                        case 0:
                            result = new string[0];
                            break;

                        case 1:
                            throw new ProviderException(SR.GetString("The role '{0}' was not found.", roleName));

                        default:
                            throw new ProviderException(SR.GetString("Stored procedure call failed."));
                        }
                    }
                    else
                    {
                        string[] array = new string[stringCollection.Count];
                        stringCollection.CopyTo(array, 0);
                        result = array;
                    }
                }
                finally
                {
                    if (sqlConnectionHolder != null)
                    {
                        sqlConnectionHolder.Close();
                        sqlConnectionHolder = null;
                    }
                }
            }
            catch
            {
                throw;
            }
            return(result);
        }