ManagementAuthorization.Grant(String, String, Boolean) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Grants authorization to a user name or role for the specified configuration path.
public:
static Microsoft::Web::Management::Server::ManagementAuthorizationInfo ^ Grant(System::String ^ name, System::String ^ configurationPath, bool isRole);
public static Microsoft.Web.Management.Server.ManagementAuthorizationInfo Grant (string name, string configurationPath, bool isRole);
static member Grant : string * string * bool -> Microsoft.Web.Management.Server.ManagementAuthorizationInfo
Public Shared Function Grant (name As String, configurationPath As String, isRole As Boolean) As ManagementAuthorizationInfo
Parameters
- name
- String
The user name to be granted permission.
- configurationPath
- String
The configuration path for which authorization will be granted.
- isRole
- Boolean
true
to indicate that the value specified in the name
parameter is a security role; otherwise, false
.
Returns
A ManagementAuthorizationInfo object.
Exceptions
name
is null
or empty.
Examples
The following example demonstrates the Grant method. This example checks to see whether the specified user is already in the collection of authorized users. If the user is not already in the collection, the Grant method grants authorization to the user. This code example is part of a larger example provided for the ManagementAuthorization class.
// Grant the user permission to this site only if
// they are not already in the allowed users collection.
if (!isInCollection)
{
ManagementAuthorization.Grant(userName, path, false);
message = message + "\nadded: " + userName;
}
display = display + message;
Remarks
This method inserts a user into the collection of authorized users for the specified path. After the user is granted permission to the site, the user is included in the collection returned by the GetAuthorizedUsers method and in the list of users on the IIS Manager Permissions page in IIS Manager.
This method constructs a new ManagementAuthorizationInfo object that has the name
, configurationPath
, and isRole
parameter values. Granting authorization to a user modifies the Administration.config file.
Attempting to grant authorization to a user who is already in the authorized-users collection will throw an exception.