-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
SqlRoleProvider.xml
879 lines (712 loc) · 54.5 KB
/
SqlRoleProvider.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
<Type Name="SqlRoleProvider" FullName="System.Web.Security.SqlRoleProvider">
<TypeSignature Language="C#" Value="public class SqlRoleProvider : System.Web.Security.RoleProvider" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi beforefieldinit SqlRoleProvider extends System.Web.Security.RoleProvider" />
<TypeSignature Language="DocId" Value="T:System.Web.Security.SqlRoleProvider" />
<TypeSignature Language="VB.NET" Value="Public Class SqlRoleProvider
Inherits RoleProvider" />
<TypeSignature Language="F#" Value="type SqlRoleProvider = class
 inherit RoleProvider" />
<TypeSignature Language="C++ CLI" Value="public ref class SqlRoleProvider : System::Web::Security::RoleProvider" />
<AssemblyInfo>
<AssemblyName>System.Web</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Web.Security.RoleProvider</BaseTypeName>
</Base>
<Interfaces />
<Docs>
<summary>Manages storage of role membership information for an ASP.NET application in a SQL Server database.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This class is used by the <xref:System.Web.Security.Roles> and <xref:System.Web.Security.RolePrincipal> classes to provide role-management services for an ASP.NET application using a SQL Server database. You can use role management to specify different levels of authorization for your application.
To use the <xref:System.Web.Security.SqlRoleProvider> class, you must first create the SQL Server database used by the <xref:System.Web.Security.SqlRoleProvider>. To create the database used by the <xref:System.Web.Security.SqlRoleProvider> class, run the `aspnet_regsql.exe` executable found in the C:\WINDOWS\Microsoft.NET\Framework\ `versionNumber` folder and specify the `-Ar` option (for example, `aspnet_regsql.exe -Ar`). The database created is called Aspnetdb. Alternatively, run aspnet_regsql.exe to pull up the GUI configuration mode and choose to configure all ASP.NET features.
If the role provider is configured with a connection string that uses integrated security, the process account of the ASP.NET application must have rights to connect to the SQL Server database.
The Machine.config file is configured with a <xref:System.Web.Security.SqlRoleProvider> instance named AspNetSqlProvider that connects to the SQL Server on the local machine. You can use this instance of the provider, or specify your own in the Web.config file for your ASP.NET application. To use the AspNetSqlProvider instance, specify AspNetSqlProvider as the `defaultProvider` in your configuration.
You can configure the <xref:System.Web.Security.SqlRoleProvider> to use the same database and user information as the <xref:System.Web.Security.SqlMembershipProvider> in order to use a single database for authentication and authorization information. To use the same database for membership and role information, run the aspnet_regsql.exe executable and install the membership feature. Then, specify the same connection string in your configuration for both your <xref:System.Web.Security.SqlRoleProvider> and <xref:System.Web.Security.SqlMembershipProvider> instances. Also ensure that both provider instances are configured with the same <xref:System.Web.Security.SqlRoleProvider.ApplicationName%2A>.
## Examples
The following example shows the Web.config file for an ASP.NET application configured to use a <xref:System.Web.Security.SqlRoleProvider> object and the <xref:System.Web.Security.SqlMembershipProvider>. The `authorization` element is configured to only allow access to authenticated users in the Administrators role.
```
<configuration>
<connectionStrings>
<add name="SqlServices" connectionString="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=aspnetdb;" />
</connectionStrings>
<system.web>
<authentication mode="Forms" >
<forms loginUrl="logincs.aspx"
name=".ASPXFORMSAUTH" />
</authentication>
<authorization>
<deny users="?" />
<allow roles="Administrators" />
<deny users="*" />
</authorization>
<membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15">
<providers>
<add
name="SqlProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="SqlServices"
enablePasswordRetrieval="false"
enablePasswordReset="false"
requiresQuestionAndAnswer="false"
passwordFormat="Hashed"
applicationName="SampleApplication" />
</providers>
</membership>
<roleManager defaultProvider="SqlProvider"
enabled="true"
cacheRolesInCookie="true"
cookieName=".ASPROLES"
cookieTimeout="30"
cookiePath="/"
cookieRequireSSL="true"
cookieSlidingExpiration="true"
cookieProtection="All" >
<providers>
<add
name="SqlProvider"
type="System.Web.Security.SqlRoleProvider"
connectionStringName="SqlServices"
applicationName="SampleApplication" />
</providers>
</roleManager>
</system.web>
</configuration>
```
]]></format>
</remarks>
<related type="Article" href="https://learn.microsoft.com/previous-versions/aspnet/5k850zwb(v=vs.100)">Understanding ASP.NET Role Management</related>
</Docs>
<Members>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public SqlRoleProvider ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Web.Security.SqlRoleProvider.#ctor" />
<MemberSignature Language="VB.NET" Value="Public Sub New ()" />
<MemberSignature Language="C++ CLI" Value="public:
 SqlRoleProvider();" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<Parameters />
<Docs>
<summary>Creates an instance of the <see cref="T:System.Web.Security.SqlRoleProvider" /> class.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Web.Security.SqlRoleProvider.%23ctor%2A> constructor is called by ASP.NET to create an instance of the <xref:System.Web.Security.SqlRoleProvider> class as specified in the configuration for the application. This constructor is not intended to be used from your code.
]]></format>
</remarks>
<related type="Article" href="https://learn.microsoft.com/previous-versions/aspnet/5k850zwb(v=vs.100)">Understanding ASP.NET Role Management</related>
</Docs>
</Member>
<Member MemberName="AddUsersToRoles">
<MemberSignature Language="C#" Value="public override void AddUsersToRoles (string[] usernames, string[] roleNames);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig virtual instance void AddUsersToRoles(string[] usernames, string[] roleNames) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Web.Security.SqlRoleProvider.AddUsersToRoles(System.String[],System.String[])" />
<MemberSignature Language="VB.NET" Value="Public Overrides Sub AddUsersToRoles (usernames As String(), roleNames As String())" />
<MemberSignature Language="F#" Value="override this.AddUsersToRoles : string[] * string[] -> unit" Usage="sqlRoleProvider.AddUsersToRoles (usernames, roleNames)" />
<MemberSignature Language="C++ CLI" Value="public:
 override void AddUsersToRoles(cli::array <System::String ^> ^ usernames, cli::array <System::String ^> ^ roleNames);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="usernames" Type="System.String[]" />
<Parameter Name="roleNames" Type="System.String[]" />
</Parameters>
<Docs>
<param name="usernames">A string array of user names to be added to the specified roles.</param>
<param name="roleNames">A string array of role names to add the specified user names to.</param>
<summary>Adds the specified user names to each of the specified roles.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Web.Security.SqlRoleProvider.AddUsersToRoles%2A> method is called by the <xref:System.Web.Security.Roles> class to associate one or more users with one or more roles in the SQL Server database specified in the ASP.NET application's configuration file (Web.config). This method is called by the <xref:System.Web.Security.Roles.AddUserToRole%2A>, <xref:System.Web.Security.Roles.AddUserToRoles%2A>, <xref:System.Web.Security.Roles.AddUsersToRole%2A>, and <xref:System.Web.Security.Roles.AddUsersToRoles%2A> methods of the <xref:System.Web.Security.Roles> class.
The database updates that are performed during the call to the <xref:System.Web.Security.SqlRoleProvider.AddUsersToRoles%2A> method are made within a transaction. If an error is encountered, such as a user name that is already in a specified role, the transaction is rolled back and no updates are performed.
If the <xref:System.Web.Security.SqlRoleProvider> is being used with the <xref:System.Web.Security.SqlMembershipProvider>, and one of the specified user names does not exist in the database, the user name will be automatically added to the database.
User names and role names cannot contain commas.
## Examples
The following code example adds one or more users to a role or removes a user from a role. For an example of a Web.config file that enables role management, see <xref:System.Web.Security.SqlRoleProvider>.
:::code language="aspx-csharp" source="~/snippets/csharp/VS_Snippets_WebNet/System.Web.Security.SqlRoleProvider/CS/adduserstorolecs.aspx" id="Snippet3":::
:::code language="aspx-vb" source="~/snippets/visualbasic/VS_Snippets_WebNet/System.Web.Security.SqlRoleProvider/VB/adduserstorolevb.aspx" id="Snippet3":::
]]></format>
</remarks>
<exception cref="T:System.ArgumentNullException">One of the roles in <paramref name="roleNames" /> is <see langword="null" />.
-or-
One of the users in <paramref name="usernames" /> is <see langword="null" />.</exception>
<exception cref="T:System.ArgumentException">One of the roles in <paramref name="roleNames" /> is an empty string or contains a comma.
-or-
One of the users in <paramref name="usernames" /> is an empty string or contains a comma.
-or-
One of the roles in <paramref name="roleNames" /> is longer than 256 characters.
-or-
One of the users in <paramref name="usernames" /> is longer than 256 characters.
-or-
<paramref name="roleNames" /> contains a duplicate element.
-or-
<paramref name="usernames" /> contains a duplicate element.</exception>
<exception cref="T:System.Configuration.Provider.ProviderException">One or more of the specified role names was not found.
-or-
One or more of the specified user names was not found.
-or-
One or more of the specified user names is already associated with one or more of the specified role names.
-or-
An unknown error occurred while communicating with the database.</exception>
<related type="Article" href="https://learn.microsoft.com/previous-versions/aspnet/5k850zwb(v=vs.100)">Understanding ASP.NET Role Management</related>
</Docs>
</Member>
<Member MemberName="ApplicationName">
<MemberSignature Language="C#" Value="public override string ApplicationName { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property instance string ApplicationName" />
<MemberSignature Language="DocId" Value="P:System.Web.Security.SqlRoleProvider.ApplicationName" />
<MemberSignature Language="VB.NET" Value="Public Overrides Property ApplicationName As String" />
<MemberSignature Language="F#" Value="member this.ApplicationName : string with get, set" Usage="System.Web.Security.SqlRoleProvider.ApplicationName" />
<MemberSignature Language="C++ CLI" Value="public:
 virtual property System::String ^ ApplicationName { System::String ^ get(); void set(System::String ^ value); };" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets or sets the name of the application for which to store and retrieve role information.</summary>
<value>The name of the application for which to store and retrieve role information. The default is the <see cref="P:System.Web.HttpRequest.ApplicationPath" /> property value for the current <see cref="P:System.Web.HttpContext.Request" />.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Web.Security.SqlRoleProvider.ApplicationName%2A> is used by the <xref:System.Web.Security.SqlRoleProvider> to associate users and roles with different applications. This enables multiple applications to use the same database to store user and role information without running into conflicts between duplicate user names or role names. Multiple ASP.NET applications can use the same database by specifying the same value in the <xref:System.Web.Security.SqlRoleProvider.ApplicationName%2A> property. The <xref:System.Web.Security.SqlRoleProvider.ApplicationName%2A> property can be set programmatically, or it can be set declaratively in the configuration file for the Web application using the `applicationName` attribute.
If a value is not specified for the `applicationName` attribute in the configuration file for the Web application, then the <xref:System.Web.HttpRequest.ApplicationPath%2A?displayProperty=nameWithType> property value for the current <xref:System.Web.HttpContext.Request%2A?displayProperty=nameWithType> object is used.
> [!CAUTION]
> Because a single default role provider instance is used for all of the requests served by an <xref:System.Web.HttpApplication> object, you can have multiple requests executing concurrently and attempting to set the <xref:System.Web.Security.SqlRoleProvider.ApplicationName%2A> property value. The <xref:System.Web.Security.SqlRoleProvider.ApplicationName%2A> property is not thread safe for multiple writes, and changing the <xref:System.Web.Security.SqlRoleProvider.ApplicationName%2A> property value can result in unexpected behavior for multiple users of an application. It is recommended that you avoid writing code that allows users to set the <xref:System.Web.Security.SqlRoleProvider.ApplicationName%2A> property unless you must. An example of an application where setting the <xref:System.Web.Security.SqlRoleProvider.ApplicationName%2A> property may be required is an administrative application that manages role data for multiple applications. Such an application should be a single-user application and not a Web application.
## Examples
The following example shows the `roleManager` element in the `system.web` section of the Web.config file for an ASP.NET application. It specifies the application's <xref:System.Web.Security.SqlRoleProvider> instance and sets the <xref:System.Web.Security.SqlRoleProvider.ApplicationName%2A> property to `MyApplication`.
```
<roleManager defaultProvider="SqlProvider"
enabled="true"
cacheRolesInCookie="true"
cookieName=".ASPROLES"
cookieTimeout="30"
cookiePath="/"
cookieRequireSSL="false"
cookieSlidingExpiration="true"
cookieProtection="All" >
<providers>
<add
name="SqlProvider"
type="System.Web.Security.SqlRoleProvider"
connectionStringName="SqlServices"
applicationName="MyApplication" />
</providers>
</roleManager>
```
]]></format>
</remarks>
<exception cref="T:System.Web.HttpException">An attempt was made to set the <see cref="P:System.Web.Security.SqlRoleProvider.ApplicationName" /> property by a caller that does not have <see cref="F:System.Web.AspNetHostingPermissionLevel.High" /> ASP.NET hosting permission.</exception>
<exception cref="T:System.Configuration.Provider.ProviderException">An attempt was made to set the <see cref="P:System.Web.Security.SqlRoleProvider.ApplicationName" /> to a string that is longer than 256 characters.</exception>
<related type="Article" href="https://learn.microsoft.com/previous-versions/aspnet/5k850zwb(v=vs.100)">Understanding ASP.NET Role Management</related>
</Docs>
</Member>
<Member MemberName="CreateRole">
<MemberSignature Language="C#" Value="public override void CreateRole (string roleName);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig virtual instance void CreateRole(string roleName) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Web.Security.SqlRoleProvider.CreateRole(System.String)" />
<MemberSignature Language="VB.NET" Value="Public Overrides Sub CreateRole (roleName As String)" />
<MemberSignature Language="F#" Value="override this.CreateRole : string -> unit" Usage="sqlRoleProvider.CreateRole roleName" />
<MemberSignature Language="C++ CLI" Value="public:
 override void CreateRole(System::String ^ roleName);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="roleName" Type="System.String" />
</Parameters>
<Docs>
<param name="roleName">The name of the role to create.</param>
<summary>Adds a new role to the role database.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Web.Security.SqlRoleProvider.CreateRole%2A> method is called by the <xref:System.Web.Security.Roles> class to create a role in the SQL Server database specified in the ASP.NET application's configuration file (Web.config).
The maximum length for the role name is 256 characters. Role names are not case-sensitive. Commas are not allowed in role names.
## Examples
The following code example creates a new role in the database. For an example of a Web.config file that enables role management, see <xref:System.Web.Security.SqlRoleProvider>.
> [!IMPORTANT]
> This example contains a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see [Script Exploits Overview](https://learn.microsoft.com/previous-versions/aspnet/w1sw53ds(v=vs.100)).
:::code language="aspx-csharp" source="~/snippets/csharp/VS_Snippets_WebNet/System.Web.Security.SqlRoleProvider/CS/createrolecs.aspx" id="Snippet1":::
:::code language="aspx-vb" source="~/snippets/visualbasic/VS_Snippets_WebNet/System.Web.Security.SqlRoleProvider/VB/createrolevb.aspx" id="Snippet1":::
]]></format>
</remarks>
<exception cref="T:System.ArgumentNullException">
<paramref name="roleName" /> is <see langword="null" />.</exception>
<exception cref="T:System.ArgumentException">
<paramref name="roleName" /> is an empty string or contains a comma.
-or-
<paramref name="roleName" /> is longer than 256 characters.</exception>
<exception cref="T:System.Configuration.Provider.ProviderException">
<paramref name="roleName" /> already exists in the database.
-or-
An unknown error occurred while communicating with the database.</exception>
<related type="Article" href="https://learn.microsoft.com/previous-versions/aspnet/5k850zwb(v=vs.100)">Understanding ASP.NET Role Management</related>
</Docs>
</Member>
<Member MemberName="DeleteRole">
<MemberSignature Language="C#" Value="public override bool DeleteRole (string roleName, bool throwOnPopulatedRole);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig virtual instance bool DeleteRole(string roleName, bool throwOnPopulatedRole) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Web.Security.SqlRoleProvider.DeleteRole(System.String,System.Boolean)" />
<MemberSignature Language="VB.NET" Value="Public Overrides Function DeleteRole (roleName As String, throwOnPopulatedRole As Boolean) As Boolean" />
<MemberSignature Language="F#" Value="override this.DeleteRole : string * bool -> bool" Usage="sqlRoleProvider.DeleteRole (roleName, throwOnPopulatedRole)" />
<MemberSignature Language="C++ CLI" Value="public:
 override bool DeleteRole(System::String ^ roleName, bool throwOnPopulatedRole);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="roleName" Type="System.String" />
<Parameter Name="throwOnPopulatedRole" Type="System.Boolean" />
</Parameters>
<Docs>
<param name="roleName">The name of the role to delete.</param>
<param name="throwOnPopulatedRole">If <see langword="true" />, throws an exception if <paramref name="roleName" /> has one or more members.</param>
<summary>Removes a role from the role database.</summary>
<returns>
<see langword="true" /> if the role was successfully deleted; otherwise, <see langword="false" />.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Web.Security.SqlRoleProvider.DeleteRole%2A> method is called by the <xref:System.Web.Security.Roles> class to delete a role from the SQL Server database specified in the ASP.NET application's configuration file (Web.config). When a role is deleted, the list of users associated with that role is also deleted from the database. The user information in the database is not affected.
If `throwOnPopulatedRole` is `true`, then an exception will be thrown and the role will not be deleted if the role identified by the `roleName` parameter has one or more members. If `throwOnPopulatedRole` is `false`, then the role will be deleted whether it is empty or not.
## Examples
The following example deletes a role from the database. For an example of a Web.config file that enables role management, see <xref:System.Web.Security.SqlRoleProvider>.
:::code language="aspx-csharp" source="~/snippets/csharp/VS_Snippets_WebNet/System.Web.Security.SqlRoleProvider/CS/deleterolecs.aspx" id="Snippet2":::
:::code language="aspx-vb" source="~/snippets/visualbasic/VS_Snippets_WebNet/System.Web.Security.SqlRoleProvider/VB/deleterolevb.aspx" id="Snippet2":::
]]></format>
</remarks>
<exception cref="T:System.ArgumentNullException">
<paramref name="roleName" /> is <see langword="null" /> (<see langword="Nothing" /> in Visual Basic).</exception>
<exception cref="T:System.ArgumentException">
<paramref name="roleName" /> is an empty string or contains a comma.
-or-
<paramref name="roleName" /> is longer than 256 characters.</exception>
<exception cref="T:System.Configuration.Provider.ProviderException">
<paramref name="roleName" /> has one or more members and <paramref name="throwOnPopulatedRole" /> is <see langword="true" />.
-or-
An unknown error occurred while communicating with the database.</exception>
<related type="Article" href="https://learn.microsoft.com/previous-versions/aspnet/5k850zwb(v=vs.100)">Understanding ASP.NET Role Management</related>
</Docs>
</Member>
<Member MemberName="FindUsersInRole">
<MemberSignature Language="C#" Value="public override string[] FindUsersInRole (string roleName, string usernameToMatch);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig virtual instance string[] FindUsersInRole(string roleName, string usernameToMatch) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Web.Security.SqlRoleProvider.FindUsersInRole(System.String,System.String)" />
<MemberSignature Language="VB.NET" Value="Public Overrides Function FindUsersInRole (roleName As String, usernameToMatch As String) As String()" />
<MemberSignature Language="F#" Value="override this.FindUsersInRole : string * string -> string[]" Usage="sqlRoleProvider.FindUsersInRole (roleName, usernameToMatch)" />
<MemberSignature Language="C++ CLI" Value="public:
 override cli::array <System::String ^> ^ FindUsersInRole(System::String ^ roleName, System::String ^ usernameToMatch);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String[]</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="roleName" Type="System.String" />
<Parameter Name="usernameToMatch" Type="System.String" />
</Parameters>
<Docs>
<param name="roleName">The role to search in.</param>
<param name="usernameToMatch">The user name to search for.</param>
<summary>Gets an array of user names in a role where the user name contains the specified user name to match.</summary>
<returns>A string array containing the names of all the users where the user name matches <paramref name="usernameToMatch" /> and the user is a member of the specified role.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Web.Security.SqlRoleProvider.FindUsersInRole%2A> method is called by the <xref:System.Web.Security.Roles> class and returns a list of users in a role where the user name contains a match of the supplied `usernameToMatch` for the configured `applicationName`. The <xref:System.Web.Security.SqlRoleProvider> searches for a user name that matches the `usernameToMatch` parameter value using the LIKE keyword and supports SQL Server wildcard characters. For example, if the `usernameToMatch` parameter is set to "user1", then membership information for the user with the user name of "user1" is returned, if it exists. If the `usernameToMatch` parameter is set to "user%", then membership information for users with the user name of "user1", "user2", "user_admin", and so on are returned.
## Examples
The following code example uses the <xref:System.Web.Security.Roles.FindUsersInRole%2A> method to display role membership based on user input. For an example of a Web.config file that enables role management, see <xref:System.Web.Security.Roles>.
> [!IMPORTANT]
> This example contains a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see [Script Exploits Overview](https://learn.microsoft.com/previous-versions/aspnet/w1sw53ds(v=vs.100)).
:::code language="aspx-csharp" source="~/snippets/csharp/VS_Snippets_WebNet/System.Web.Security.Roles/CS/FindUsersInRolecs.aspx" id="Snippet11":::
:::code language="aspx-vb" source="~/snippets/visualbasic/VS_Snippets_WebNet/System.Web.Security.Roles/VB/FindUsersInRolevb.aspx" id="Snippet11":::
]]></format>
</remarks>
<exception cref="T:System.ArgumentNullException">
<paramref name="roleName" /> is <see langword="null" /> (<see langword="Nothing" /> in Visual Basic).
-or-
<paramref name="usernameToMatch" /> is <see langword="null" />.</exception>
<exception cref="T:System.ArgumentException">
<paramref name="roleName" /> is an empty string or contains a comma.
-or-
<paramref name="usernameToMatch" /> is an empty string.
-or-
<paramref name="roleName" /> is longer than 256 characters.
-or-
<paramref name="usernameToMatch" /> is longer than 256 characters.</exception>
<exception cref="T:System.Configuration.Provider.ProviderException">
<paramref name="roleName" /> was not found in the database.
-or-
An unknown error occurred while communicating with the database.</exception>
<related type="Article" href="https://learn.microsoft.com/previous-versions/aspnet/5k850zwb(v=vs.100)">Understanding ASP.NET Role Management</related>
</Docs>
</Member>
<Member MemberName="GetAllRoles">
<MemberSignature Language="C#" Value="public override string[] GetAllRoles ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig virtual instance string[] GetAllRoles() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Web.Security.SqlRoleProvider.GetAllRoles" />
<MemberSignature Language="VB.NET" Value="Public Overrides Function GetAllRoles () As String()" />
<MemberSignature Language="F#" Value="override this.GetAllRoles : unit -> string[]" Usage="sqlRoleProvider.GetAllRoles " />
<MemberSignature Language="C++ CLI" Value="public:
 override cli::array <System::String ^> ^ GetAllRoles();" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String[]</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Gets a list of all the roles for the application.</summary>
<returns>A string array containing the names of all the roles stored in the database for a particular application.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Web.Security.SqlRoleProvider.GetAllRoles%2A> method is called by the <xref:System.Web.Security.Roles> class to retrieve a list of all the roles in the SQL Server database specified in the ASP.NET application's configuration file (Web.config).
## Examples
The following code example uses the <xref:System.Web.Security.Roles.GetAllRoles%2A> method to get the list of roles for an application and bind the results to a <xref:System.Web.UI.WebControls.GridView?displayProperty=nameWithType> control. For an example of a Web.config file that enables role management, see <xref:System.Web.Security.SqlRoleProvider>.
> [!IMPORTANT]
> This example contains a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see [Script Exploits Overview](https://learn.microsoft.com/previous-versions/aspnet/w1sw53ds(v=vs.100)).
:::code language="aspx-csharp" source="~/snippets/csharp/VS_Snippets_WebNet/System.Web.Security.SqlRoleProvider/CS/createrolecs.aspx" id="Snippet1":::
:::code language="aspx-vb" source="~/snippets/visualbasic/VS_Snippets_WebNet/System.Web.Security.SqlRoleProvider/VB/createrolevb.aspx" id="Snippet1":::
]]></format>
</remarks>
<exception cref="T:System.Configuration.Provider.ProviderException">An unknown error occurred while communicating with the database.</exception>
<related type="Article" href="https://learn.microsoft.com/previous-versions/aspnet/5k850zwb(v=vs.100)">Understanding ASP.NET Role Management</related>
</Docs>
</Member>
<Member MemberName="GetRolesForUser">
<MemberSignature Language="C#" Value="public override string[] GetRolesForUser (string username);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig virtual instance string[] GetRolesForUser(string username) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Web.Security.SqlRoleProvider.GetRolesForUser(System.String)" />
<MemberSignature Language="VB.NET" Value="Public Overrides Function GetRolesForUser (username As String) As String()" />
<MemberSignature Language="F#" Value="override this.GetRolesForUser : string -> string[]" Usage="sqlRoleProvider.GetRolesForUser username" />
<MemberSignature Language="C++ CLI" Value="public:
 override cli::array <System::String ^> ^ GetRolesForUser(System::String ^ username);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String[]</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="username" Type="System.String" />
</Parameters>
<Docs>
<param name="username">The user to return a list of roles for.</param>
<summary>Gets a list of the roles that a user is in.</summary>
<returns>A string array containing the names of all the roles that the specified user is in.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Web.Security.SqlRoleProvider.GetRolesForUser%2A> method is called by the <xref:System.Web.Security.Roles> class to retrieve a list of a specified user's roles from the SQL Server database specified in the ASP.NET application's configuration file (Web.config).
## Examples
The following code example uses the <xref:System.Web.Security.Roles.GetRolesForUser%2A> method to retrieve a list of roles for a specified user and binds them to a <xref:System.Web.UI.WebControls.GridView?displayProperty=nameWithType> control. For an example of a Web.config file that enables role management, see <xref:System.Web.Security.SqlRoleProvider>.
:::code language="aspx-csharp" source="~/snippets/csharp/VS_Snippets_WebNet/System.Web.Security.SqlRoleProvider/CS/ViewRolescs.aspx" id="Snippet4":::
:::code language="aspx-vb" source="~/snippets/visualbasic/VS_Snippets_WebNet/System.Web.Security.SqlRoleProvider/VB/ViewRolesvb.aspx" id="Snippet4":::
]]></format>
</remarks>
<exception cref="T:System.ArgumentNullException">
<paramref name="username" /> is <see langword="null" />.</exception>
<exception cref="T:System.ArgumentException">
<paramref name="username" /> contains a comma.
-or-
<paramref name="username" /> is longer than 256 characters.</exception>
<exception cref="T:System.Configuration.Provider.ProviderException">An unknown error occurred while communicating with the database.</exception>
<related type="Article" href="https://learn.microsoft.com/previous-versions/aspnet/5k850zwb(v=vs.100)">Understanding ASP.NET Role Management</related>
</Docs>
</Member>
<Member MemberName="GetUsersInRole">
<MemberSignature Language="C#" Value="public override string[] GetUsersInRole (string roleName);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig virtual instance string[] GetUsersInRole(string roleName) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Web.Security.SqlRoleProvider.GetUsersInRole(System.String)" />
<MemberSignature Language="VB.NET" Value="Public Overrides Function GetUsersInRole (roleName As String) As String()" />
<MemberSignature Language="F#" Value="override this.GetUsersInRole : string -> string[]" Usage="sqlRoleProvider.GetUsersInRole roleName" />
<MemberSignature Language="C++ CLI" Value="public:
 override cli::array <System::String ^> ^ GetUsersInRole(System::String ^ roleName);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String[]</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="roleName" Type="System.String" />
</Parameters>
<Docs>
<param name="roleName">The name of the role to get the list of users for.</param>
<summary>Gets a list of users in the specified role.</summary>
<returns>A string array containing the names of all the users who are members of the specified role.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Web.Security.SqlRoleProvider.GetUsersInRole%2A> method is called by the <xref:System.Web.Security.Roles> class to retrieve the list of users associated with the specified role in the SQL Server database specified in the ASP.NET application's configuration file (Web.config).
## Examples
The following code example uses the <xref:System.Web.Security.Roles.GetUsersInRole%2A> method to get a list of the users in a particular role and bind the results to a <xref:System.Web.UI.WebControls.GridView?displayProperty=nameWithType> control. For an example of a Web.config file that enables role management, see <xref:System.Web.Security.SqlRoleProvider>.
:::code language="aspx-csharp" source="~/snippets/csharp/VS_Snippets_WebNet/System.Web.Security.SqlRoleProvider/CS/adduserstorolecs.aspx" id="Snippet3":::
:::code language="aspx-vb" source="~/snippets/visualbasic/VS_Snippets_WebNet/System.Web.Security.SqlRoleProvider/VB/adduserstorolevb.aspx" id="Snippet3":::
]]></format>
</remarks>
<exception cref="T:System.ArgumentNullException">
<paramref name="roleName" /> is <see langword="null" />.</exception>
<exception cref="T:System.ArgumentException">
<paramref name="roleName" /> is an empty string or contains a comma.
-or-
<paramref name="roleName" /> is longer than 256 characters.</exception>
<exception cref="T:System.Configuration.Provider.ProviderException">
<paramref name="rolename" /> was not found in the database.
-or-
An unknown error occurred while communicating with the database.</exception>
<related type="Article" href="https://learn.microsoft.com/previous-versions/aspnet/5k850zwb(v=vs.100)">Understanding ASP.NET Role Management</related>
</Docs>
</Member>
<Member MemberName="Initialize">
<MemberSignature Language="C#" Value="public override void Initialize (string name, System.Collections.Specialized.NameValueCollection config);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig virtual instance void Initialize(string name, class System.Collections.Specialized.NameValueCollection config) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Web.Security.SqlRoleProvider.Initialize(System.String,System.Collections.Specialized.NameValueCollection)" />
<MemberSignature Language="VB.NET" Value="Public Overrides Sub Initialize (name As String, config As NameValueCollection)" />
<MemberSignature Language="F#" Value="override this.Initialize : string * System.Collections.Specialized.NameValueCollection -> unit" Usage="sqlRoleProvider.Initialize (name, config)" />
<MemberSignature Language="C++ CLI" Value="public:
 override void Initialize(System::String ^ name, System::Collections::Specialized::NameValueCollection ^ config);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="name" Type="System.String" />
<Parameter Name="config" Type="System.Collections.Specialized.NameValueCollection" />
</Parameters>
<Docs>
<param name="name">The name of the <see cref="T:System.Web.Security.SqlRoleProvider" /> instance to initialize.</param>
<param name="config">A <see cref="T:System.Collections.Specialized.NameValueCollection" /> that contains the names and values of configuration options for the role provider.</param>
<summary>Initializes the SQL Server role provider with the property values specified in the ASP.NET application's configuration file. This method is not intended to be used directly from your code.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This method initializes the <xref:System.Web.Security.SqlRoleProvider> with the property values specified in the ASP.NET application configuration file (Web.config) and is not intended to be used directly from your code.
]]></format>
</remarks>
<exception cref="T:System.Web.HttpException">The ASP.NET application is not running at <see cref="F:System.Web.AspNetHostingPermissionLevel.Medium" /> trust or higher.</exception>
<exception cref="T:System.ArgumentNullException">
<paramref name="config" /> is <see langword="null" />.</exception>
<exception cref="T:System.Configuration.Provider.ProviderException">The <see langword="connectionStringName" /> attribute is empty or does not exist in the application configuration file for this <see cref="T:System.Web.Security.SqlRoleProvider" /> instance.
-or-
The <see langword="applicationName" /> attribute exceeds 256 characters.
-or-
The application configuration file for this <see cref="T:System.Web.Security.SqlRoleProvider" /> instance contains an unrecognized attribute.</exception>
<related type="Article" href="https://learn.microsoft.com/previous-versions/aspnet/5k850zwb(v=vs.100)">Understanding ASP.NET Role Management</related>
</Docs>
</Member>
<Member MemberName="IsUserInRole">
<MemberSignature Language="C#" Value="public override bool IsUserInRole (string username, string roleName);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig virtual instance bool IsUserInRole(string username, string roleName) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Web.Security.SqlRoleProvider.IsUserInRole(System.String,System.String)" />
<MemberSignature Language="VB.NET" Value="Public Overrides Function IsUserInRole (username As String, roleName As String) As Boolean" />
<MemberSignature Language="F#" Value="override this.IsUserInRole : string * string -> bool" Usage="sqlRoleProvider.IsUserInRole (username, roleName)" />
<MemberSignature Language="C++ CLI" Value="public:
 override bool IsUserInRole(System::String ^ username, System::String ^ roleName);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="username" Type="System.String" />
<Parameter Name="roleName" Type="System.String" />
</Parameters>
<Docs>
<param name="username">The user name to search for.</param>
<param name="roleName">The role to search in.</param>
<summary>Gets a value indicating whether the specified user is in the specified role.</summary>
<returns>
<see langword="true" /> if the specified user name is in the specified role; otherwise, <see langword="false" />.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Web.Security.SqlRoleProvider.IsUserInRole%2A> method is called by the <xref:System.Web.Security.Roles> class and the <xref:System.Security.Principal.IPrincipal.IsInRole%2A> method of the <xref:System.Web.UI.Page.User%2A?displayProperty=nameWithType> property to determine whether a user is associated with a role in the SQL Server database specified in the ASP.NET application's configuration file (Web.config).
## Examples
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 <xref:System.Web.Security.SqlRoleProvider>.
:::code language="aspx-csharp" source="~/snippets/csharp/VS_Snippets_WebNet/System.Web.Security.SqlRoleProvider/CS/ViewRolescs.aspx" id="Snippet4":::
:::code language="aspx-vb" source="~/snippets/visualbasic/VS_Snippets_WebNet/System.Web.Security.SqlRoleProvider/VB/ViewRolesvb.aspx" id="Snippet4":::
]]></format>
</remarks>
<exception cref="T:System.ArgumentNullException">
<paramref name="roleName" /> is <see langword="null" />.
-or-
<paramref name="username" /> is <see langword="null" />.</exception>
<exception cref="T:System.ArgumentException">
<paramref name="roleName" /> is an empty string or contains a comma.
-or-
<paramref name="username" /> is contains a comma.
-or-
<paramref name="roleName" /> is longer than 256 characters.
-or-
<paramref name="username" /> is longer than 256 characters.</exception>
<exception cref="T:System.Configuration.Provider.ProviderException">An unknown error occurred while communicating with the database.</exception>
<related type="Article" href="https://learn.microsoft.com/previous-versions/aspnet/5k850zwb(v=vs.100)">Understanding ASP.NET Role Management</related>
</Docs>
</Member>
<Member MemberName="RemoveUsersFromRoles">
<MemberSignature Language="C#" Value="public override void RemoveUsersFromRoles (string[] usernames, string[] roleNames);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig virtual instance void RemoveUsersFromRoles(string[] usernames, string[] roleNames) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Web.Security.SqlRoleProvider.RemoveUsersFromRoles(System.String[],System.String[])" />
<MemberSignature Language="VB.NET" Value="Public Overrides Sub RemoveUsersFromRoles (usernames As String(), roleNames As String())" />
<MemberSignature Language="F#" Value="override this.RemoveUsersFromRoles : string[] * string[] -> unit" Usage="sqlRoleProvider.RemoveUsersFromRoles (usernames, roleNames)" />
<MemberSignature Language="C++ CLI" Value="public:
 override void RemoveUsersFromRoles(cli::array <System::String ^> ^ usernames, cli::array <System::String ^> ^ roleNames);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="usernames" Type="System.String[]" />
<Parameter Name="roleNames" Type="System.String[]" />
</Parameters>
<Docs>
<param name="usernames">A string array of user names to be removed from the specified roles.</param>
<param name="roleNames">A string array of role names to remove the specified user names from.</param>
<summary>Removes the specified user names from the specified roles.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Web.Security.SqlRoleProvider.RemoveUsersFromRoles%2A> method is called by the <xref:System.Web.Security.Roles> class to remove one or more users from one or more roles in the SQL Server database specified in the ASP.NET application's configuration file (Web.config). This method is called by the <xref:System.Web.Security.Roles.RemoveUserFromRole%2A>, <xref:System.Web.Security.Roles.RemoveUserFromRoles%2A>, <xref:System.Web.Security.Roles.RemoveUsersFromRole%2A>, and <xref:System.Web.Security.Roles.RemoveUsersFromRoles%2A> methods of the <xref:System.Web.Security.Roles> class.
The database updates that are performed during the call to <xref:System.Web.Security.SqlRoleProvider.RemoveUsersFromRoles%2A> are made within a transaction. If an error is encountered, such as a user name that does not exist or a user name that is already in a specified role, the transaction is rolled back and no updates are performed.
User names and role names cannot contain commas.
## Examples
The following code example adds one or more users to a role or removes a user from a role. For an example of a Web.config file that enables role management, see <xref:System.Web.Security.SqlRoleProvider>.
:::code language="aspx-csharp" source="~/snippets/csharp/VS_Snippets_WebNet/System.Web.Security.SqlRoleProvider/CS/adduserstorolecs.aspx" id="Snippet3":::
:::code language="aspx-vb" source="~/snippets/visualbasic/VS_Snippets_WebNet/System.Web.Security.SqlRoleProvider/VB/adduserstorolevb.aspx" id="Snippet3":::
]]></format>
</remarks>
<exception cref="T:System.ArgumentNullException">One of the roles in <paramref name="roleNames" /> is <see langword="null" />.
-or-
One of the users in <paramref name="usernames" /> is <see langword="null" />.</exception>
<exception cref="T:System.ArgumentException">One of the roles in <paramref name="roleNames" /> is an empty string or contains a comma.
-or-
One of the users in <paramref name="usernames" /> is an empty string or contains a comma.
-or-
One of the roles in <paramref name="roleNames" /> is longer than 256 characters.
-or-
One of the users in <paramref name="usernames" /> is longer than 256 characters.
-or-
<paramref name="roleNames" /> contains a duplicate element.
-or-
<paramref name="usernames" /> contains a duplicate element.</exception>
<exception cref="T:System.Configuration.Provider.ProviderException">One or more of the specified user names was not found.
-or-
One or more of the specified role names was not found.
-or-
One or more of the specified user names is not associated with one or more of the specified role names.
-or-
An unknown error occurred while communicating with the database.</exception>
<related type="Article" href="https://learn.microsoft.com/previous-versions/aspnet/5k850zwb(v=vs.100)">Understanding ASP.NET Role Management</related>
</Docs>
</Member>
<Member MemberName="RoleExists">
<MemberSignature Language="C#" Value="public override bool RoleExists (string roleName);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig virtual instance bool RoleExists(string roleName) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Web.Security.SqlRoleProvider.RoleExists(System.String)" />
<MemberSignature Language="VB.NET" Value="Public Overrides Function RoleExists (roleName As String) As Boolean" />
<MemberSignature Language="F#" Value="override this.RoleExists : string -> bool" Usage="sqlRoleProvider.RoleExists roleName" />
<MemberSignature Language="C++ CLI" Value="public:
 override bool RoleExists(System::String ^ roleName);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="roleName" Type="System.String" />
</Parameters>
<Docs>
<param name="roleName">The name of the role to search for in the database.</param>
<summary>Gets a value indicating whether the specified role name already exists in the role database.</summary>
<returns>
<see langword="true" /> if the role name already exists in the database; otherwise, <see langword="false" />.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Web.Security.SqlRoleProvider.RoleExists%2A> method is called by the <xref:System.Web.Security.Roles> class to determine whether a role name exists in the SQL Server database specified in the ASP.NET application's configuration file (Web.config).
## Examples
The following code example uses the <xref:System.Web.Security.Roles.RoleExists%2A> method to determine whether a role name already exists before creating the role. For an example of a Web.config file that enables role management, see <xref:System.Web.Security.SqlRoleProvider>.
> [!IMPORTANT]
> This example contains a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see [Script Exploits Overview](https://learn.microsoft.com/previous-versions/aspnet/w1sw53ds(v=vs.100)).
:::code language="aspx-csharp" source="~/snippets/csharp/VS_Snippets_WebNet/System.Web.Security.SqlRoleProvider/CS/createrolecs.aspx" id="Snippet1":::
:::code language="aspx-vb" source="~/snippets/visualbasic/VS_Snippets_WebNet/System.Web.Security.SqlRoleProvider/VB/createrolevb.aspx" id="Snippet1":::
]]></format>
</remarks>
<exception cref="T:System.ArgumentNullException">
<paramref name="roleName" /> is <see langword="null" />.</exception>
<exception cref="T:System.ArgumentException">
<paramref name="roleName" /> is an empty string or contains a comma.
-or-
<paramref name="roleName" /> is longer than 256 characters.</exception>
<exception cref="T:System.Configuration.Provider.ProviderException">An unknown error occurred while communicating with the database.</exception>
<related type="Article" href="https://learn.microsoft.com/previous-versions/aspnet/5k850zwb(v=vs.100)">Understanding ASP.NET Role Management</related>
</Docs>
</Member>
</Members>
</Type>