AuthorizationStoreRoleProvider.DeleteRole(String, Boolean) Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Authorization-manager ilke deposundan bir rolü kaldırır.
public:
override bool DeleteRole(System::String ^ roleName, bool throwOnPopulatedRole);
public override bool DeleteRole(string roleName, bool throwOnPopulatedRole);
override this.DeleteRole : string * bool -> bool
Public Overrides Function DeleteRole (roleName As String, throwOnPopulatedRole As Boolean) As Boolean
Parametreler
- roleName
- String
Silinecek rolün adı.
- throwOnPopulatedRole
- Boolean
ise true, bir veya daha fazla üyesi varsa roleName bir özel durum oluşturur.
Döndürülenler
true rol silindiyse; aksi takdirde , false.
Özel durumlar
roleName, null değeridir.
roleName bir veya daha fazla üyesi vardır ve throwOnPopulatedRole şeklindedir true.
-veya-
Yapılandırılan applicationName bulunamadı.
-veya-
Yapılandırılan scopeName bulunamadı.
-veya-
Authorization-manager çalışma zamanı sunucuda yüklü değil.
connectionStringName özniteliği, var olmayan bir dosyaya bağlantı dizesine başvurur.
Örnek AuthorizationStoreRoleProvider dosya tabanlı bir ilke deposuyla yapılandırılır ve geçerli güven düzeyinde dosyaya okuma erişimine izin verilmez.
Örnekler
Aşağıdaki örnek, authorization-manager ilke deposundan bir rolü siler. Rol yönetimini etkinleştiren bir Web.config dosyası örneği için bkz AuthorizationStoreRoleProvider. .
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Security" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
string[] rolesArray;
public void Page_Load(object sender, EventArgs args)
{
if (!IsPostBack)
{
// Bind roles to ListBox.
rolesArray = Roles.GetAllRoles();
RolesListBox.DataSource = rolesArray;
RolesListBox.DataBind();
}
}
public void DeleteRole_OnClick(object sender, EventArgs args)
{
string delRole = "";
try
{
delRole = RolesListBox.SelectedItem.Value;
Roles.DeleteRole(delRole);
Msg.Text = "Role '" + Server.HtmlEncode(delRole) + "' deleted.";
// Re-bind roles to ListBox.
rolesArray = Roles.GetAllRoles();
RolesListBox.DataSource = rolesArray;
RolesListBox.DataBind();
}
catch
{
Msg.Text = "Role '" + Server.HtmlEncode(delRole) + "' <u>not</u> deleted.";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Sample: Delete Role</title>
</head>
<body>
<form runat="server" id="PageForm">
<h3>
Delete Role</h3>
<asp:Label ID="Msg" ForeColor="maroon" runat="server" /><br />
<table border="0">
<tr>
<td valign="top">
Delete Role:</td>
<td valign="top">
<asp:ListBox ID="RolesListBox" runat="server" Rows="8" /></td>
<td valign="top">
<asp:Button Text="Delete Role" ID="DeleteRoleButton" runat="server" OnClick="DeleteRole_OnClick" /></td>
</tr>
</table>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Web.Security" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Dim rolesArray() As String
Public Sub Page_Load(ByVal sender As Object, ByVal args As EventArgs)
If Not IsPostBack Then
' Bind roles to ListBox.
rolesArray = Roles.GetAllRoles()
RolesListBox.DataSource = rolesArray
RolesListBox.DataBind()
End If
End Sub
Public Sub DeleteRole_OnClick(ByVal sender As Object, ByVal args As EventArgs)
Dim delRole As String
Try
delRole = RolesListBox.SelectedItem.Value
Roles.DeleteRole(delRole)
Msg.Text = "Role '" & Server.HtmlEncode(delRole) & "' deleted."
' Re-bind roles to ListBox.
rolesArray = Roles.GetAllRoles()
RolesListBox.DataSource = rolesArray
RolesListBox.DataBind()
Catch
Msg.Text = "Role '" & Server.HtmlEncode(delRole) & "' <u>not</u> deleted."
End Try
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Sample: Delete Role</title>
</head>
<body>
<form runat="server" id="PageForm">
<h3>
Delete Role</h3>
<asp:Label ID="Msg" ForeColor="maroon" runat="server" /><br />
<table border="0">
<tr>
<td valign="top">
Delete Role:</td>
<td valign="top">
<asp:ListBox ID="RolesListBox" runat="server" Rows="8" /></td>
<td valign="top">
<asp:Button Text="Delete Role" ID="DeleteRoleButton" runat="server" OnClick="DeleteRole_OnClick" /></td>
</tr>
</table>
</form>
</body>
</html>
Açıklamalar
yöntemi DeleteRole , ASP.NET uygulamasının Roles yapılandırma dosyasında (Web.config) belirtilen authorization-manager ilke deposundan bir rolü silmek için sınıfı tarafından çağrılır. Bir rol silindiğinde, bu rolle ilişkili kullanıcıların listesi de ilke deposundan silinir. Veritabanındaki kullanıcı bilgileri etkilenmez.
ise throwOnPopulatedRoletrue, bir özel durum oluşturulur ve parametresi tarafından roleName tanımlanan rolün bir veya daha fazla üyesi varsa rol silinmez. ise throwOnPopulatedRolefalse, rol boş olsa da olmasa da silinir.