The OracleRoleProvider
class allows ASP.NET applications to store role and user information in an Oracle database.
System.Object
System.Configuration.Provider.ProviderBase
System.Web.Security.RoleProvider
Oracle.Web.Security
// C# public class OracleRoleProvider : RoleProvider
All public static methods are thread-safe, although instance members are not guaranteed to be thread-safe.
This class allows ASP.NET applications to store and manage role information in an Oracle database.
Note that the role information that this provider manages are application roles and not database roles.
The following is a web.config
example for an ASP.NET application that uses the OracleRoleProvider
class as the default provider. This configuration uses the connection string and default attribute values specified in the machine.config
file:
<?xml version="1.0"?> <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> <system.web> <roleManager enabled="true" defaultProvider="OracleRoleProvider"/> </system.web> </configuration>
The following is a web.config
example for an ASP.NET application that uses an OracleRoleProvider
as the default provider with customized settings and an application-specific connection string.
<?xml version="1.0"?> <configuration xmlns= "http://schemas.microsoft.com/.NetConfiguration/v2.0"> <connectionStrings> <add name="my_role_app_con_string" connectionString= "User Id=scott;Password=tiger;Data Source=Oracle"/> </connectionStrings> <system.web> <!-- Enable and customize OracleRoleProvider --> <roleManager enabled="true" defaultProvider="MyOracleRoleProvider"> <providers> <add name="MyOracleRoleProvider" type="Oracle.Web.Security.OracleRoleProvider, Oracle.Web, Version=2.112.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" connectionStringName="my_role_app_con_string" applicationName="my_role_app"/> </providers> </roleManager> </system.web> </configuration>
Note that the applicationName
attribute should be set to a unique value for each ASP.NET application.
Namespace: Oracle.Web.Security
Assembly: Oracle.Web.dll
Oracle Providers for ASP.NET Version: Oracle Providers for ASP.NET 2.0 and Oracle Providers for ASP.NET 4
See Also:
OracleRoleProvider
members are listed in the following tables.
OracleRoleProvider Constructors
The OracleRoleProvider
constructor is listed in Table 3-1.
Table 3-1 OracleRoleProvider Constructor
Constructor | Description |
---|---|
Instantiates a new instance of the |
OracleRoleProvider Static Methods
OracleRoleProvider
static methods are listed in Table 3-2.
Table 3-2 OracleRoleProvider Static Methods
Static Methods | Description |
---|---|
|
Inherited from |
|
Inherited from |
OracleRoleProvider Public Properties
OracleRoleProvider
public properties are listed in Table 3-3.
Table 3-3 OracleRoleProvider Public Properties
Public Properties | Description |
---|---|
Gets or sets the name of the application that stores the role provider information |
|
Gets the number of seconds that the command is allowed to execute before it is terminated with an exception |
|
|
Inherited from |
|
Inherited from |
OracleRoleProvider Public Methods
OracleRoleProvider
public methods are listed in Table 3-4.
Table 3-4 OracleRoleProvider Public Methods
Public Methods | Description |
---|---|
Adds the specified users to the specified roles |
|
Adds a new role to the database |
|
Deletes a role in the database |
|
|
Inherited from |
Returns an array of user names that match the specified user name |
|
Returns an array of all the roles for an application |
|
|
Inherited from |
Returns an array of role names for the specified user |
|
|
Inherited from |
Returns an array of users in the specified role name |
|
Initializes |
|
Indicates whether the specified user is in the specified role |
|
Removes the specified array of users from the specified array of role names |
|
Indicates whether the specified role name exists in the database |
|
|
Inherited from |
OracleRoleProvider
constructors create instances of the OracleRoleProvider
class.
This constructor creates an instance of the OracleRoleProvider
class.
See Also:
The OracleRoleProvider
static methods are listed in Table 3-5.
The OracleRoleProvider
public properties are listed in Table 3-6.
Table 3-6 OracleRoleProvider Public Properties
Public Properties | Description |
---|---|
Gets or sets the name of the application that stores the role provider information |
|
Gets the number of seconds that the command is allowed to execute before it is terminated with an exception |
|
|
Inherited from |
|
Inherited from |
See Also:
This property gets or sets the name of the application that stores the role provider information.
// C# public override string ApplicationName{get; set;};
The name of the application. If the applicationName
attribute is not specified in the application configuration file, or if the value is an empty string, then this property is set to the application virtual path.
HttpException
- The user setting the ApplicationName
property does not have high ASP.NET hosting permission.
System.Configuration.Provider.ProviderException
- The ApplicationName
property is set to a string greater than 256 characters.
The string value of the ApplicationName
property is used to associate user names and role names with different applications. Multiple applications can use the same database to store user names and role names without running into any conflict between duplicate names. This property can be set programmatically, or it can be set declaratively in the Web application configuration file using the applicationName
attribute. The attribute name in the configuration file is case-sensitive.
The ApplicationName
property is not thread-safe. It is recommended that the programming code not allow users to set the ApplicationName
property in Web applications.
This property gets the number of seconds that the command is allowed to execute before it is terminated with an exception.
// C# public int CommandTimeout {get;}
An int
.
To customize a provider, ASP.NET developers can set an integer value for this property through the web.config
file using the commandTimeout
attribute.
The default value is 30 seconds. The attribute name in the configuration file is case-sensitive.
The OracleRoleProvider
public methods are listed in Table 3-7.
Table 3-7 OracleRoleProvider Public Methods
Public Method | Description |
---|---|
Adds the specified users to the specified roles |
|
Adds a new role to the database |
|
Deletes a role in the database |
|
|
Inherited from |
Returns an array of user names that match the specified user name |
|
Returns an array of all the roles for an application |
|
|
Inherited from |
Returns an array of role names for the specified user |
|
|
Inherited from |
Returns an array of users in the specified role name |
|
Initializes |
|
Indicates whether the specified user is in the specified role |
|
Removes the specified array of users from the specified array of role names |
|
Indicates whether the specified role name exists in the database |
|
|
Inherited from |
See Also:
This method adds the specified users to the specified roles.
// C# public override void AddUsersToRoles(string[] userNames, string[] roleNames);
userNames
An array of user names to be added to roles.
roleNames
An array of role names to add the user names to.
ArgumentNullException
- One of the users in userNames
or one of the roles in roleNames
is null.
ArgumentException
- Either the roleNames
or userNames
parameter is an empty string, contains a comma, is longer than 256 characters, or contains a duplicate element.
System.Configuration.Provider.ProviderException
- One or more role names were not found, or one or more user names are already associated with one or more role names.
OracleException
- An Oracle-related error has occurred.
This method adds one or more user names to one or more of the specified roles. The updates are performed in a transaction. If an error occurs, then the transaction is rolled back and no updates are made.
If one of the user names does not exist in the database, then the user name will be created and added to the database.
This method adds a new role to the database.
// C#
public override void CreateRole(string roleName);
roleName
The role name to be created in the database.
ArgumentNullException
- The roleName
parameter is null.
ArgumentException
- The roleName
parameter is an empty string, contains a comma, or is longer than 256 characters.
System.Configuration.Provider.ProviderException
- The role name already exists in the database.
OracleException
- An Oracle-related error has occurred.
This method creates a new role in the database.
This method deletes a role in the database.
// C# public override bool DeleteRole(string roleName, bool throwOnPopulatedRole);
roleName
The role name to be deleted from the database.
throwOnPopulatedRole
A Boolean value that, if set to true
, causes an exception if the role contains any user names. If the value is set to false
, deletes the role from the database.
Returns true
if the specified role was successfully deleted; otherwise, returns false
.
ArgumentNullException
- The roleName
parameter is null.
System.Configuration.Provider.ProviderException
- The role name contains at least one user name and the throwOnPopulatedRole
parameter is set to true
.
OracleException
- An Oracle-related error has occurred.
ArgumentException
- The roleName
parameter is an empty string, contains a comma, or is longer than 256 characters:
If the throwOnPopulatedRole
parameter is set to false
, then it deletes the specified role from the database regardless of whether it contains any users. If the throwOnPopulatedRole
parameter is set to true
, then an exception is thrown if the specified role in the database contains any users, but the role is not deleted.
This method returns an array of user names that match the specified user name, for the specified role name.
// C# public override string[ ] FindUsersInRole(string roleName, string userNameToMatch);
roleName
The role name being searched for in the database.
userNameToMatch
The user name being searched for.
A string array that contains user names in the specified role that match the specified userNameToMatch
parameter.
ArgumentNullException
- The roleName
or userNameToMatch
parameter is null.
OracleException
- An Oracle-related error has occurred.
System.Configuration.Provider.ProviderException
- The role name does not exist in the database.
ArgumentException
- One of the following conditions exists:
The roleName
parameter is an empty string, contains a comma, or is longer than 256 characters.
The userNameToMatch
parameter is an empty string or is longer than 256 characters.
This method returns an array of user names that match the specified user name, for the specified role name. This method supports Oracle wildcard characters. If the userNameToMatch
parameter is set to "oraUser%"
, then an array is returned for users such as "oraUser1"
, "oraUser2"
, and so on. However, if the userNameToMatch
parameter is set to "oraUser"
, then the array is returned with just the username "oraUser"
, if there is an "oraUser"
.
This method returns an array of all the roles for an application.
// C# public override string[ ] GetAllRoles();
A string array containing all the role names in a database for the application.
OracleException
- An Oracle related error has occurred.
This method returns an array of role names for the specified user.
// C#
public override string[] GetRolesForUser(string userName);
userName
The user name for which an array of role names is returned.
An array of role names for the specified user name.
ArgumentNullException
- The userName
parameter is null.
ArgumentException
- The userName
parameter contains a comma or is longer than 256 characters.
OracleException
- An Oracle-related error has occurred.
This method returns an array of users in the specified role name.
// C#
public override string[ ] GetUsersInRole(string roleName);
roleName
The role name for which an array of users is returned.
An array of user names in the specified role name.
ArgumentNullException
- The roleName
parameter is null.
OracleException
- An Oracle-related error has occurred.
System.Configuration.Provider.ProviderException
- The role name does not exist in the database.
ArgumentException
- The roleName
parameter is an empty string, contains a comma, or is longer than 256 characters:
This method initializes the OracleRoleProvider
instance with the property values specified in the ASP.NET application configuration file (web.config
).
// C# public override void Initialize(string name, NameValueCollection config);
name
The name of the OracleRoleProvider
instance to initialize.
config
A Systems.Collections.Specialized.NameValueCollection
object that contains the names and values of configuration options for the role provider.
System.Web.HttpException
- ASP.NET is not running at medium trust or higher.
ArgumentNullException
- The config
parameter is null.
System.Configuration.Provider.ProviderException
- The connectionStringName
attribute is empty or does not exist in the configuration file, the applicationName
attribute exceeds 256 characters, or the configuration file contains an invalid attribute.
The Initialize
method is not intended to be called directly by the application.
This method indicates whether the specified user is in the specified role.
// C# public override bool IsUserInRole(string userName, string roleName);
userName
The user name being searched for.
roleName
The role name being searched in.
Returns true
if the specified user name is in the specified role name; otherwise, returns false
.
ArgumentNullException
- The userName
or roleName
parameter is null.
OracleException
- An Oracle-related error has occurred.
ArgumentException
- One of the following conditions exists:
The roleName
parameter is an empty string, contains a comma, or is longer than 256 characters.
The userName
parameter contains a comma or is longer than 256 characters.
This method determines if the specified user name exists in the specified role name in the database.
This method removes the specified array of users from the specified array of role names.
// C# public override void RemoveUsersFromRoles(string[] userNames, string[] roleNames);
userNames
An array of user names to remove from the role names.
roleNames
An array of role names to remove the user names from.
ArgumentNullException
- One of the users in the userNames
parameter or one of the roles in the roleNames
parameter is null.
OracleException
- An Oracle-related error has occurred.
System.Configuration.Provider.ProviderException
- One or more of the role names or user names does not exist in the database, or one or more of the user names is not associated a role name.
ArgumentException
- The roleNames
or userNames
parameter is an empty string, contains a comma, is longer than 256 characters, or contains a duplicate element.
This method removes the specified array of user names from the specified array of role names. The updates are made within a transaction. If an error occurs, the transaction is rolled back.
This method indicates whether the specified role name exists in the database.
// C#
public override bool RoleExists(string roleName);
roleName
The role name being searched for in the database.
Returns true
if the role name exists; otherwise, returns false
.
ArgumentNullException
- The roleName
parameter is null
OracleException
- An Oracle-related error has occurred.
ArgumentException
- The roleName
parameter is an empty string, contains a comma, or is longer than 256 characters.