SqlRoleProvider.IsUserInRole Method
.NET Framework 3.0
Gets a value indicating whether the specified user is in the specified role.
Namespace: System.Web.Security
Assembly: System.Web (in system.web.dll)
Assembly: System.Web (in system.web.dll)
public boolean IsUserInRole ( String username, String roleName )
public override function IsUserInRole ( username : String, roleName : String ) : boolean
Not applicable.
Parameters
- username
The user name to search for.
- roleName
The role to search in.
Return Value
true if the specified user name is in the specified role; otherwise, false.| Exception type | Condition |
|---|---|
|
roleName is a null reference (Nothing in Visual Basic). -or- username is a null reference (Nothing in Visual Basic). | |
|
roleName is an empty string or contains a comma. -or- username is contains a comma. -or- roleName is longer than 256 characters. -or- username is longer than 256 characters. | |
|
An unknown error occurred while communicating with the database. |
The following code example programmatically checks to see whether the logged-on user is in the Administrators role before allowing the user to view user roles. For an example of a Web.config file that enables role management, see SqlRoleProvider.
Community Additions
ADD
Show: