download SqlRoleProvider.cs
Language: C#
Copyright: (c) 2005,2006 Novell, Inc (http://www.novell.com) (C) 2003 Ben Maurer
LOC: 420
Project Info
mcs
Server: Mono
Type: svn
...em.Web\System.Web.Security\
   ...ConnectionProtection.cs
   ...ryMembershipProvider.cs
   ...ntificationEventArgs.cs
   ...ficationEventHandler.cs
   ...IdentificationModule.cs
   CookieProtection.cs
   ...henticationEventArgs.cs
   ...ticationEventHandler.cs
   ...AuthenticationModule.cs
   FileAuthorizationModule.cs
   FormsAuthentication.cs
   ...henticationEventArgs.cs
   ...ticationEventHandler.cs
   ...AuthenticationModule.cs
   ...AuthenticationTicket.cs
   FormsIdentity.cs
   Membership.cs
   MembershipCreateStatus.cs
   ...pCreateUserException.cs
   MembershipOnlineStatus.cs
   ...hipPasswordException.cs
   ...ershipPasswordFormat.cs
   MembershipProvider.cs
   ...ipProviderCollection.cs
   MembershipSortOptions.cs
   MembershipUser.cs
   ...ershipUserCollection.cs
   ...PasswordEventHandler.cs
   ...henticationEventArgs.cs
   ...ticationEventHandler.cs
   ...AuthenticationModule.cs
   PassportIdentity.cs
   RoleManagerEventArgs.cs
   RoleManagerEventHandler.cs
   RoleManagerModule.cs
   RolePrincipal.cs
   RoleProvider.cs
   RoleProviderCollection.cs
   Roles.cs
   SqlMembershipProvider.cs
   SqlRoleProvider.cs
   UrlAuthorizationModule.cs
   ...atePasswordEventArgs.cs
   ...henticationEventArgs.cs
   ...ticationEventHandler.cs
   ...AuthenticationModule.cs

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
//
// System.Web.Security.SqlRoleProvider
//
// Authors:
//	Ben Maurer (bmaurer@users.sourceforge.net)
//	Chris Toshok (toshok@ximian.com)
//
// (C) 2003 Ben Maurer
// Copyright (c) 2005,2006 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#if NET_2_0

using System.Collections;
using System.Collections.Specialized;
using System.Data;
using System.Data.Common;
using System.Configuration;
using System.Configuration.Provider;
using System.Web.Configuration;

namespace System.Web.Security {

	public class SqlRoleProvider: RoleProvider {

		string applicationName;

		ConnectionStringSettings connectionString;
		DbProviderFactory factory;

		DbConnection CreateConnection ()
		{
			DbConnection connection = factory.CreateConnection ();
			connection.ConnectionString = connectionString.ConnectionString;

			connection.Open ();
			return connection;
		}

		void AddParameter (DbCommand command, string parameterName, string parameterValue)
		{
			DbParameter dbp = command.CreateParameter ();
			dbp.ParameterName = parameterName;
			dbp.Value = parameterValue;
			dbp.Direction = ParameterDirection.Input;
			command.Parameters.Add (dbp);
		}

		public override void AddUsersToRoles (string [] usernames, string [] rolenames)
		{
			string commandText = @"
INSERT INTO dbo.aspnet_UsersInRoles (UserId, RoleId)
     SELECT dbo.aspnet_Users.UserId, dbo.aspnet_Roles.RoleId 
       FROM dbo.aspnet_Users, dbo.aspnet_Roles, dbo.aspnet_Applications
      WHERE dbo.aspnet_Users.ApplicationId = dbo.aspnet_Applications.ApplicationId
        AND dbo.aspnet_Roles.ApplicationId = dbo.aspnet_Applications.ApplicationId
        AND dbo.aspnet_Applications.LoweredApplicationName = LOWER(@ApplicationName)
        AND dbo.aspnet_Users.LoweredUserName = LOWER(@UserName)
        AND dbo.aspnet_Roles.LoweredRoleName = LOWER(@RoleName)
";

			Hashtable h;

			h = new Hashtable();
			foreach (string u in usernames) {
				if (u == null)
					throw new ArgumentNullException ("null element in usernames array");
				if (h.ContainsKey (u))
					throw new ArgumentException ("duplicate element in usernames array");
				if (u.Length == 0 || u.Length > 256 || u.IndexOf (",") != -1)
					throw new ArgumentException ("element in usernames array in illegal format");
				h.Add (u, u);
			}

			h = new Hashtable();
			foreach (string r in usernames) {
				if (r == null)
					throw new ArgumentNullException ("null element in usernames array");
				if (h.ContainsKey (r))
					throw new ArgumentException ("duplicate element in usernames array");
				if (r.Length == 0 || r.Length > 256 || r.IndexOf (",") != -1)
					throw new ArgumentException ("element in usernames array in illegal format");
				h.Add (r, r);
			}

			using(DbConnection connection = CreateConnection ()) {

			DbTransaction trans = connection.BeginTransaction ();

			try {
				foreach (string username in usernames) {

					foreach (string rolename in rolenames) {

						/* add the user/role combination to dbo.aspnet_UsersInRoles */
						DbCommand command = factory.CreateCommand ();
						command.Transaction = trans;
						command.CommandText = commandText;
						command.Connection = connection;
						command.CommandType = CommandType.Text;
						AddParameter (command, "RoleName", rolename);
						AddParameter (command, "UserName", username);
						AddParameter (command, "ApplicationName", ApplicationName);

						if (command.ExecuteNonQuery() != 1)
							throw new ProviderException ("failed to create new user/role association.");
					}
				}
				
				trans.Commit ();
			}
			catch (Exception e) {
				trans.Rollback ();
				if (e is ProviderException)
					throw e;
				else
					throw new ProviderException ("", e);
			}
			}
		}
		
		public override void CreateRole (string rolename)
		{
			string commandText = @"
INSERT INTO dbo.aspnet_Roles 
            (ApplicationId, RoleName, LoweredRoleName)
     VALUES ((SELECT ApplicationId FROM dbo.aspnet_Applications WHERE LoweredApplicationName = LOWER(@ApplicationName)), @RoleName, LOWER(@RoleName))
";
			if (rolename == null)
				throw new ArgumentNullException ("rolename");

			if (rolename.Length == 0 || rolename.Length > 256 || rolename.IndexOf (",") != -1)
				throw new ArgumentException ("rolename is in invalid format");

			using (DbConnection connection = CreateConnection ()) {

			DbCommand command = factory.CreateCommand ();
			command.CommandText = commandText;
			command.Connection = connection;
			command.CommandType = CommandType.Text;
			AddParameter (command, "ApplicationName", ApplicationName);
			AddParameter (command, "RoleName", rolename);

			if (command.ExecuteNonQuery() != 1)
				throw new ProviderException ("failed to create new role.");

			}
		}
		
		[MonoTODO]
		public override bool DeleteRole (string rolename, bool throwOnPopulatedRole)
		{
			if (rolename == null)
				throw new ArgumentNullException ("rolename");

			if (rolename.Length == 0 || rolename.Length > 256 || rolename.IndexOf (",") != -1)
				throw new ArgumentException ("rolename is in invalid format");

			using(DbConnection connection = CreateConnection ()) {

			DbCommand command;
			if (throwOnPopulatedRole) {
				command = factory.CreateCommand ();
				command.CommandText = @"
SELECT COUNT(*) 
  FROM dbo.aspnet_UsersInRoles, dbo.aspnet_Roles, dbo.aspnet_Users, dbo.aspnet_Applications
 WHERE dbo.aspnet_Roles.ApplicationId = dbo.aspnet_Applications.ApplicationId
   AND dbo.aspnet_UsersInRoles.RoleId = dbo.aspnet_Roles.RoleId
   AND dbo.aspnet_Applications.LoweredApplicationName = LOWER(@ApplicationName)
   AND dbo.aspnet_Roles.LoweredRoleName = LOWER(@RoleName)";
				command.Connection = connection;
				command.CommandType = CommandType.Text;
				AddParameter (command, "ApplicationName", ApplicationName);
				AddParameter (command, "RoleName", rolename);

				int count = (int)command.ExecuteScalar ();
				if (count != 0)
					throw new ProviderException (String.Format ("The role '{0}' has users in it and can't be deleted", rolename));
			}
			else {
				/* XXX are we really supposed to delete all the user/role associations in this case? */
				command = factory.CreateCommand ();
				command.CommandText = @"
DELETE dbo.aspnet_UsersInRoles FROM dbo.aspnet_UsersInRoles, dbo.aspnet_Roles, dbo.aspnet_Applications
 WHERE dbo.aspnet_UsersInRoles.RoleId = dbo.aspnet_Roles.RoleId
   AND dbo.aspnet_Roles.ApplicationId = dbo.aspnet_Applications.ApplicationId
   AND dbo.aspnet_Roles.LoweredRoleName = LOWER(@RoleName)
   AND dbo.aspnet_Applications.LoweredApplicationName = LOWER(@ApplicationName)";
				command.Connection = connection;
				command.CommandType = CommandType.Text;
				AddParameter (command, "RoleName", rolename);
				AddParameter (command, "ApplicationName", ApplicationName);

				command.ExecuteNonQuery ();
			}

			command = factory.CreateCommand ();
			command.CommandText = @"
DELETE dbo.aspnet_Roles FROM dbo.aspnet_Roles, dbo.aspnet_Applications
 WHERE dbo.aspnet_Roles.ApplicationId = dbo.aspnet_Applications.ApplicationId
   AND dbo.aspnet_Applications.LoweredApplicationName = LOWER(@ApplicationName)
   AND dbo.aspnet_Roles.LoweredRoleName = LOWER(@RoleName)";
			command.Connection = connection;
			command.CommandType = CommandType.Text;
			AddParameter (command, "ApplicationName", ApplicationName);
			AddParameter (command, "RoleName", rolename);

			bool rv = command.ExecuteNonQuery() == 1;

			return rv;
			}
		}
		
		public override string[] FindUsersInRole (string roleName, string usernameToMatch)
		{
			string commandTextFormat = @"
SELECT dbo.aspnet_Users.UserName
  FROM dbo.aspnet_Users, dbo.aspnet_Roles, dbo.aspnet_UsersInRoles, dbo.aspnet_Applications
 WHERE dbo.aspnet_Roles.ApplicationId = dbo.aspnet_Applications.ApplicationId
   AND dbo.aspnet_Users.ApplicationId = dbo.aspnet_Applications.ApplicationId
   AND dbo.aspnet_UsersInRoles.UserId = dbo.aspnet_Users.UserId
   AND dbo.aspnet_UsersInRoles.RoleId = dbo.aspnet_Roles.RoleId
   AND dbo.aspnet_Roles.LoweredRoleName = LOWER(@RoleName)
   AND dbo.aspnet_Applications.LoweredApplicationName = LOWER(@ApplicationName)
   AND dbo.aspnet_Users.UserName {0} @UsernameToMatch
";
			if (roleName == null)
				throw new ArgumentNullException ("roleName");
			if (usernameToMatch == null)
				throw new ArgumentNullException ("usernameToMatch");

			if (roleName.Length == 0 || roleName.Length > 256 || roleName.IndexOf (",") != -1)
				throw new ArgumentException ("roleName is in invalid format");
			if (usernameToMatch.Length == 0 || usernameToMatch.Length > 256)
				throw new ArgumentException ("usernameToMatch is in invalid format");

			using(DbConnection connection = CreateConnection ()) {

			bool useLike = usernameToMatch.IndexOf ("%") != -1;
			DbCommand command = factory.CreateCommand ();
			command.CommandText = String.Format(commandTextFormat, useLike ? "LIKE" : "=");
			command.Connection = connection;
			command.CommandType = CommandType.Text;
			AddParameter (command, "ApplicationName", ApplicationName);
			AddParameter (command, "RoleName", roleName);
			AddParameter (command, "UsernameToMatch", usernameToMatch);

			DbDataReader reader = command.ExecuteReader ();
			ArrayList userList = new ArrayList();
			while (reader.Read())
				userList.Add (reader.GetString(0));
			reader.Close();

			return (string[])userList.ToArray(typeof (string));
			}
		}

		public override string [] GetAllRoles ()
		{
			string commandText = @"
SELECT dbo.aspnet_Roles.RoleName
  FROM dbo.aspnet_Roles, dbo.aspnet_Applications
 WHERE dbo.aspnet_Roles.ApplicationId = dbo.aspnet_Applications.ApplicationId
   AND dbo.aspnet_Applications.LoweredApplicationName = LOWER(@ApplicationName)
";
			using(DbConnection connection = CreateConnection ()) {

			DbCommand command = factory.CreateCommand ();
			command.CommandText = commandText;
			command.Connection = connection;
			command.CommandType = CommandType.Text;
			AddParameter (command, "ApplicationName", ApplicationName);

			DbDataReader reader = command.ExecuteReader ();
			ArrayList roleList = new ArrayList();
			while (reader.Read())
				roleList.Add (reader.GetString(0));
			reader.Close();

			return (string[])roleList.ToArray(typeof (string));
			}
		}
		
		public override string [] GetRolesForUser (string username)
		{
			string commandText = @"
SELECT dbo.aspnet_Roles.RoleName
  FROM dbo.aspnet_Roles, dbo.aspnet_UsersInRoles, dbo.aspnet_Users, dbo.aspnet_Applications
WHERE dbo.aspnet_Roles.RoleId = dbo.aspnet_UsersInRoles.RoleId
  AND dbo.aspnet_Roles.ApplicationId = dbo.aspnet_Applications.ApplicationId
  AND dbo.aspnet_UsersInRoles.UserId = dbo.aspnet_Users.UserId
  AND dbo.aspnet_Users.LoweredUserName = LOWER(@UserName)
  AND dbo.aspnet_Users.ApplicationId = dbo.aspnet_Applications.ApplicationId
  AND dbo.aspnet_Applications.LoweredApplicationName = LOWER(@ApplicationName)
";

			using(DbConnection connection = CreateConnection ()) {

			DbCommand command = factory.CreateCommand ();
			command.CommandText = commandText;
			command.Connection = connection;
			command.CommandType = CommandType.Text;
			AddParameter (command, "UserName", username);
			AddParameter (command, "ApplicationName", ApplicationName);

			DbDataReader reader = command.ExecuteReader ();
			ArrayList roleList = new ArrayList();
			while (reader.Read())
				roleList.Add (reader.GetString(0));
			reader.Close();

			return (string[])roleList.ToArray(typeof (string));
			}
		}
		
		public override string [] GetUsersInRole (string rolename)
		{
			string commandText = @"
SELECT dbo.aspnet_Users.UserName
  FROM dbo.aspnet_Roles, dbo.aspnet_UsersInRoles, dbo.aspnet_Users, dbo.aspnet_Applications
WHERE dbo.aspnet_Roles.RoleId = dbo.aspnet_UsersInRoles.RoleId
  AND dbo.aspnet_Roles.ApplicationId = dbo.aspnet_Applications.ApplicationId
  AND dbo.aspnet_UsersInRoles.UserId = dbo.aspnet_Users.UserId
  AND dbo.aspnet_Roles.LoweredRoleName = LOWER(@RoleName)
  AND dbo.aspnet_Users.ApplicationId = dbo.aspnet_Applications.ApplicationId
  AND dbo.aspnet_Applications.LoweredApplicationName = LOWER(@ApplicationName)
";

			using(DbConnection connection = CreateConnection ()) {

			DbCommand command = factory.CreateCommand ();
			command.CommandText = commandText;
			command.Connection = connection;
			command.CommandType = CommandType.Text;
			AddParameter (command, "RoleName", rolename);
			AddParameter (command, "ApplicationName", ApplicationName);

			DbDataReader reader = command.ExecuteReader ();
			ArrayList userList = new ArrayList();
			while (reader.Read())
				userList.Add (reader.GetString(0));
			reader.Close();

			return (string[])userList.ToArray(typeof (string));
			}
		}

		static string GetStringConfigValue (NameValueCollection config, string name, string def)
		{
			string rv = def;
			string val = config[name];
			if (val != null)
				rv = val;
			return rv;
		}
		
		[MonoTODO]
		public override void Initialize (string name, NameValueCollection config)
		{
			if (config == null)
				throw new ArgumentNullException ("config");

			base.Initialize (name, config);

			applicationName = config ["applicationName"];
			string connectionStringName = config["connectionStringName"];

			if (applicationName.Length > 256)
				throw new ProviderException ("The ApplicationName attribute must be 256 characters long or less.");
			if (connectionStringName == null || connectionStringName.Length == 0)
				throw new ProviderException ("The ConnectionStringName attribute must be present and non-zero length.");

			// XXX check connectionStringName and commandTimeout

			connectionString = WebConfigurationManager.ConnectionStrings[connectionStringName];
			factory = connectionString == null || String.IsNullOrEmpty (connectionString.ProviderName) ?
				System.Data.SqlClient.SqlClientFactory.Instance :
				ProvidersHelper.GetDbProviderFactory (connectionString.ProviderName);
		}
		
		public override bool IsUserInRole (string username, string rolename)
		{
			string commandText = @"
SELECT COUNT(*)
  FROM dbo.aspnet_Users, dbo.aspnet_UsersInRoles, dbo.aspnet_Roles, dbo.aspnet_Applications
 WHERE dbo.aspnet_Roles.ApplicationId = dbo.aspnet_Applications.ApplicationId
   AND dbo.aspnet_Users.ApplicationId = dbo.aspnet_Applications.ApplicationId
   AND dbo.aspnet_UsersInRoles.RoleId = dbo.aspnet_Roles.RoleId
   AND dbo.aspnet_UsersInRoles.UserId = dbo.aspnet_Users.UserId
   AND dbo.aspnet_Applications.LoweredApplicationName = LOWER(@ApplicationName)
   AND dbo.aspnet_Roles.LoweredRoleName = LOWER(@RoleName)
   AND dbo.aspnet_Users.LoweredUserName = LOWER(@UserName)
";

			using(DbConnection connection = CreateConnection ()) {

			DbCommand command = factory.CreateCommand ();
			command.CommandText = commandText;
			command.Connection = connection;
			command.CommandType = CommandType.Text;
			AddParameter (command, "RoleName", rolename);
			AddParameter (command, "UserName", username);
			AddParameter (command, "ApplicationName", ApplicationName);

			bool rv = ((int)command.ExecuteScalar ()) != 0;

			return rv;
			}
		}
		
		public override void RemoveUsersFromRoles (string [] usernames, string [] rolenames)
		{
			string commandText = @"
DELETE dbo.aspnet_UsersInRoles 
  FROM dbo.aspnet_UsersInRoles, dbo.aspnet_Users, dbo.aspnet_Roles, dbo.aspnet_Applications
 WHERE dbo.aspnet_UsersInRoles.UserId = dbo.aspnet_Users.UserId
   AND dbo.aspnet_UsersInRoles.RoleId = dbo.aspnet_Roles.RoleId
   AND dbo.aspnet_Roles.ApplicationId = dbo.aspnet_Applications.ApplicationId
   AND dbo.aspnet_Users.ApplicationId = dbo.aspnet_Applications.ApplicationId
   AND dbo.aspnet_Users.LoweredUserName = LOWER(@UserName)
   AND dbo.aspnet_Roles.LoweredRoleName = LOWER(@RoleName)
   AND dbo.aspnet_Applications.LoweredApplicationName = LOWER(@ApplicationName)";

			Hashtable h;

			h = new Hashtable();
			foreach (string u in usernames) {
				if (u == null)
					throw new ArgumentNullException ("null element in usernames array");
				if (h.ContainsKey (u))
					throw new ArgumentException ("duplicate element in usernames array");
				if (u.Length == 0 || u.Length > 256 || u.IndexOf (",") != -1)
					throw new ArgumentException ("element in usernames array in illegal format");
				h.Add (u, u);
			}

			h = new Hashtable();
			foreach (string r in usernames) {
				if (r == null)
					throw new ArgumentNullException ("null element in usernames array");
				if (h.ContainsKey (r))
					throw new ArgumentException ("duplicate element in usernames array");
				if (r.Length == 0 || r.Length > 256 || r.IndexOf (",") != -1)
					throw new ArgumentException ("element in usernames array in illegal format");
				h.Add (r, r);
			}

			using(DbConnection connection = CreateConnection ()) {

			DbTransaction trans = connection.BeginTransaction ();

			try {
				foreach (string username in usernames) {
					foreach (string rolename in rolenames) {
						DbCommand command = factory.CreateCommand ();
						command.Transaction = trans;
						command.CommandText = commandText;
						command.Connection = connection;
						command.CommandType = CommandType.Text;
						AddParameter (command, "UserName", username);
						AddParameter (command, "RoleName", rolename);
						AddParameter (command, "ApplicationName", ApplicationName);

						if (command.ExecuteNonQuery() != 1)
							throw new ProviderException (String.Format ("failed to remove users from role '{0}'.", rolename));
					}
				}
				
				trans.Commit ();
			}
			catch (Exception e) {
				trans.Rollback ();
				if (e is ProviderException)
					throw e;
				else
					throw new ProviderException ("", e);
			}
			}
		}
		
		public override bool RoleExists (string rolename)
		{
			string commandText = @"
SELECT COUNT(*)
  FROM dbo.aspnet_Roles, dbo.aspnet_Applications
 WHERE dbo.aspnet_Roles.ApplicationId = dbo.aspnet_Applications.ApplicationId
   AND dbo.aspnet_Applications.LoweredApplicationName = LOWER(@ApplicationName)
   AND dbo.aspnet_Roles.LoweredRoleName = LOWER(@RoleName)
";

			using (DbConnection connection = CreateConnection ()) {

				DbCommand command = factory.CreateCommand ();
				command.CommandText = commandText;
				command.Connection = connection;
				command.CommandType = CommandType.Text;
				AddParameter (command, "ApplicationName", ApplicationName);
				AddParameter (command, "RoleName", rolename);

				bool rv = ((int) command.ExecuteScalar ()) != 0;

				return rv;
			}
		}
		
		[MonoTODO]
		public override string ApplicationName {
			get { return applicationName; }
			set {
				applicationName = value;
			}
		}
	}
}
#endif

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us