SqlRoleProvider.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. //
  2. // System.Web.Security.SqlRoleProvider
  3. //
  4. // Authors:
  5. // Ben Maurer ([email protected])
  6. // Chris Toshok ([email protected])
  7. //
  8. // (C) 2003 Ben Maurer
  9. // Copyright (c) 2005,2006 Novell, Inc (http://www.novell.com)
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. #if NET_2_0
  31. using System.Collections;
  32. using System.Collections.Specialized;
  33. using System.Data;
  34. using System.Data.Common;
  35. using System.Configuration;
  36. using System.Configuration.Provider;
  37. using System.Web.Configuration;
  38. namespace System.Web.Security {
  39. public class SqlRoleProvider: RoleProvider {
  40. string applicationName;
  41. int commandTimeout;
  42. string providerName;
  43. ConnectionStringSettings connectionString;
  44. DbProviderFactory factory;
  45. DbConnection connection;
  46. void InitConnection ()
  47. {
  48. if (factory == null)
  49. factory = ProvidersHelper.GetDbProviderFactory (connectionString.ProviderName);
  50. if (connection == null) {
  51. connection = factory.CreateConnection();
  52. connection.ConnectionString = connectionString.ConnectionString;
  53. }
  54. }
  55. void AddParameter (DbCommand command, string parameterName, string parameterValue)
  56. {
  57. DbParameter dbp = command.CreateParameter ();
  58. dbp.ParameterName = parameterName;
  59. dbp.Value = parameterValue;
  60. dbp.Direction = ParameterDirection.Input;
  61. command.Parameters.Add (dbp);
  62. }
  63. public override void AddUsersToRoles (string [] usernames, string [] rolenames)
  64. {
  65. string commandText = @"
  66. INSERT INTO dbo.aspnet_UsersInRoles (UserId, RoleId)
  67. SELECT dbo.aspnet_Users.UserId, dbo.aspnet_Roles.RoleId
  68. FROM dbo.aspnet_Users, dbo.aspnet_Roles, dbo.aspnet_Applications
  69. WHERE dbo.aspnet_Users.ApplicationId = dbo.aspnet_Applications.ApplicationId
  70. AND dbo.aspnet_Roles.ApplicationId = dbo.aspnet_Applications.ApplicationId
  71. AND dbo.aspnet_Applications.LoweredApplicationName = LOWER(@ApplicationName)
  72. AND dbo.aspnet_Users.LoweredUserName = LOWER(@UserName)
  73. AND dbo.aspnet_Roles.LoweredRoleName = LOWER(@RoleName)
  74. ";
  75. Hashtable h;
  76. h = new Hashtable();
  77. foreach (string u in usernames) {
  78. if (u == null)
  79. throw new ArgumentNullException ("null element in usernames array");
  80. if (h.ContainsKey (u))
  81. throw new ArgumentException ("duplicate element in usernames array");
  82. if (u.Length == 0 || u.Length > 256 || u.IndexOf (",") != -1)
  83. throw new ArgumentException ("element in usernames array in illegal format");
  84. h.Add (u, u);
  85. }
  86. h = new Hashtable();
  87. foreach (string r in usernames) {
  88. if (r == null)
  89. throw new ArgumentNullException ("null element in usernames array");
  90. if (h.ContainsKey (r))
  91. throw new ArgumentException ("duplicate element in usernames array");
  92. if (r.Length == 0 || r.Length > 256 || r.IndexOf (",") != -1)
  93. throw new ArgumentException ("element in usernames array in illegal format");
  94. h.Add (r, r);
  95. }
  96. InitConnection();
  97. bool closed = connection.State == ConnectionState.Closed;
  98. if (closed)
  99. connection.Open();
  100. DbTransaction trans = connection.BeginTransaction ();
  101. try {
  102. foreach (string username in usernames) {
  103. foreach (string rolename in rolenames) {
  104. /* add the user/role combination to dbo.aspnet_UsersInRoles */
  105. DbCommand command = factory.CreateCommand ();
  106. command.Transaction = trans;
  107. command.CommandText = commandText;
  108. command.Connection = connection;
  109. command.CommandType = CommandType.Text;
  110. AddParameter (command, "RoleName", rolename);
  111. AddParameter (command, "UserName", username);
  112. AddParameter (command, "ApplicationName", ApplicationName);
  113. if (command.ExecuteNonQuery() != 1)
  114. throw new ProviderException ("failed to create new user/role association.");
  115. }
  116. }
  117. trans.Commit ();
  118. }
  119. catch (Exception e) {
  120. trans.Rollback ();
  121. if (e is ProviderException)
  122. throw e;
  123. else
  124. throw new ProviderException ("", e);
  125. }
  126. finally {
  127. if (closed)
  128. connection.Close ();
  129. }
  130. }
  131. public override void CreateRole (string rolename)
  132. {
  133. string commandText = @"
  134. INSERT INTO dbo.aspnet_Roles
  135. (ApplicationId, RoleName, LoweredRoleName)
  136. VALUES ((SELECT ApplicationId FROM dbo.aspnet_Applications WHERE LoweredApplicationName = LOWER(@ApplicationName)), @RoleName, LOWER(@RoleName))
  137. ";
  138. if (rolename == null)
  139. throw new ArgumentNullException ("rolename");
  140. if (rolename.Length == 0 || rolename.Length > 256 || rolename.IndexOf (",") != -1)
  141. throw new ArgumentException ("rolename is in invalid format");
  142. InitConnection();
  143. bool closed = connection.State == ConnectionState.Closed;
  144. if (closed)
  145. connection.Open();
  146. DbCommand command = factory.CreateCommand ();
  147. command.CommandText = commandText;
  148. command.Connection = connection;
  149. command.CommandType = CommandType.Text;
  150. AddParameter (command, "ApplicationName", ApplicationName);
  151. AddParameter (command, "RoleName", rolename);
  152. if (command.ExecuteNonQuery() != 1)
  153. throw new ProviderException ("failed to create new role.");
  154. if (closed)
  155. connection.Close ();
  156. }
  157. [MonoTODO]
  158. public override bool DeleteRole (string rolename, bool throwOnPopulatedRole)
  159. {
  160. if (rolename == null)
  161. throw new ArgumentNullException ("rolename");
  162. if (rolename.Length == 0 || rolename.Length > 256 || rolename.IndexOf (",") != -1)
  163. throw new ArgumentException ("rolename is in invalid format");
  164. InitConnection();
  165. bool closed = connection.State == ConnectionState.Closed;
  166. if (closed)
  167. connection.Open();
  168. DbCommand command;
  169. if (throwOnPopulatedRole) {
  170. command = factory.CreateCommand ();
  171. command.CommandText = @"
  172. SELECT COUNT(*)
  173. FROM dbo.aspnet_UsersInRoles, dbo.aspnet_Roles, dbo.aspnet_Users, dbo.aspnet_Applications
  174. WHERE dbo.aspnet_Roles.ApplicationId = dbo.aspnet_Applications.ApplicationId
  175. AND dbo.aspnet_UsersInRoles.RoleId = dbo.aspnet_Roles.RoleId
  176. AND dbo.aspnet_Applications.LoweredApplicationName = LOWER(@ApplicationName)
  177. AND dbo.aspnet_Roles.LoweredRoleName = LOWER(@RoleName)";
  178. command.Connection = connection;
  179. command.CommandType = CommandType.Text;
  180. AddParameter (command, "ApplicationName", ApplicationName);
  181. AddParameter (command, "RoleName", rolename);
  182. int count = (int)command.ExecuteScalar ();
  183. if (count != 0)
  184. throw new ProviderException (String.Format ("The role '{0}' has users in it and can't be deleted", rolename));
  185. }
  186. else {
  187. /* XXX are we really supposed to delete all the user/role associations in this case? */
  188. command = factory.CreateCommand ();
  189. command.CommandText = @"
  190. DELETE dbo.aspnet_UsersInRoles FROM dbo.aspnet_UsersInRoles, dbo.aspnet_Roles, dbo.aspnet_Applications
  191. WHERE dbo.aspnet_UsersInRoles.RoleId = dbo.aspnet_Roles.RoleId
  192. AND dbo.aspnet_Roles.ApplicationId = dbo.aspnet_Applications.ApplicationId
  193. AND dbo.aspnet_Roles.LoweredRoleName = LOWER(@RoleName)
  194. AND dbo.aspnet_Applications.LoweredApplicationName = LOWER(@ApplicationName)";
  195. command.Connection = connection;
  196. command.CommandType = CommandType.Text;
  197. AddParameter (command, "RoleName", rolename);
  198. AddParameter (command, "ApplicationName", ApplicationName);
  199. command.ExecuteNonQuery ();
  200. }
  201. command = factory.CreateCommand ();
  202. command.CommandText = @"
  203. DELETE dbo.aspnet_Roles FROM dbo.aspnet_Roles, dbo.aspnet_Applications
  204. WHERE dbo.aspnet_Roles.ApplicationId = dbo.aspnet_Applications.ApplicationId
  205. AND dbo.aspnet_Applications.LoweredApplicationName = LOWER(@ApplicationName)
  206. AND dbo.aspnet_Roles.LoweredRoleName = LOWER(@RoleName)";
  207. command.Connection = connection;
  208. command.CommandType = CommandType.Text;
  209. AddParameter (command, "ApplicationName", ApplicationName);
  210. AddParameter (command, "RoleName", rolename);
  211. bool rv = command.ExecuteNonQuery() == 1;
  212. if (closed)
  213. connection.Close ();
  214. return rv;
  215. }
  216. public override string[] FindUsersInRole (string roleName, string usernameToMatch)
  217. {
  218. string commandTextFormat = @"
  219. SELECT dbo.aspnet_Users.UserName
  220. FROM dbo.aspnet_Users, dbo.aspnet_Roles, dbo.aspnet_UsersInRoles, dbo.aspnet_Applications
  221. WHERE dbo.aspnet_Roles.ApplicationId = dbo.aspnet_Applications.ApplicationId
  222. AND dbo.aspnet_Users.ApplicationId = dbo.aspnet_Applications.ApplicationId
  223. AND dbo.aspnet_UsersInRoles.UserId = dbo.aspnet_Users.UserId
  224. AND dbo.aspnet_UsersInRoles.RoleId = dbo.aspnet_Roles.RoleId
  225. AND dbo.aspnet_Roles.LoweredRoleName = LOWER(@RoleName)
  226. AND dbo.aspnet_Applications.LoweredApplicationName = LOWER(@ApplicationName)
  227. AND dbo.aspnet_Users.UserName {0} @UsernameToMatch
  228. ";
  229. if (roleName == null)
  230. throw new ArgumentNullException ("roleName");
  231. if (usernameToMatch == null)
  232. throw new ArgumentNullException ("usernameToMatch");
  233. if (roleName.Length == 0 || roleName.Length > 256 || roleName.IndexOf (",") != -1)
  234. throw new ArgumentException ("roleName is in invalid format");
  235. if (usernameToMatch.Length == 0 || usernameToMatch.Length > 256)
  236. throw new ArgumentException ("usernameToMatch is in invalid format");
  237. InitConnection();
  238. bool useLike = usernameToMatch.IndexOf ("%") != -1;
  239. DbCommand command = factory.CreateCommand ();
  240. command.CommandText = String.Format(commandTextFormat, useLike ? "LIKE" : "=");
  241. command.Connection = connection;
  242. command.CommandType = CommandType.Text;
  243. AddParameter (command, "ApplicationName", ApplicationName);
  244. AddParameter (command, "RoleName", roleName);
  245. AddParameter (command, "UsernameToMatch", usernameToMatch);
  246. DbDataReader reader = command.ExecuteReader ();
  247. ArrayList userList = new ArrayList();
  248. while (reader.Read())
  249. userList.Add (reader.GetString(0));
  250. reader.Close();
  251. return (string[])userList.ToArray(typeof (string));
  252. }
  253. public override string [] GetAllRoles ()
  254. {
  255. string commandText = @"
  256. SELECT dbo.aspnet_Roles.RoleName
  257. FROM dbo.aspnet_Roles, dbo.aspnet_Applications
  258. WHERE dbo.aspnet_Roles.ApplicationId = dbo.aspnet_Applications.ApplicationId
  259. AND dbo.aspnet_Applications.LoweredApplicationName = LOWER(@ApplicationName)
  260. ";
  261. InitConnection();
  262. bool closed = connection.State == ConnectionState.Closed;
  263. if (closed)
  264. connection.Open();
  265. DbCommand command = factory.CreateCommand ();
  266. command.CommandText = commandText;
  267. command.Connection = connection;
  268. command.CommandType = CommandType.Text;
  269. AddParameter (command, "ApplicationName", ApplicationName);
  270. DbDataReader reader = command.ExecuteReader ();
  271. ArrayList roleList = new ArrayList();
  272. while (reader.Read())
  273. roleList.Add (reader.GetString(0));
  274. reader.Close();
  275. if (closed)
  276. connection.Close ();
  277. return (string[])roleList.ToArray(typeof (string));
  278. }
  279. public override string [] GetRolesForUser (string username)
  280. {
  281. string commandText = @"
  282. SELECT dbo.aspnet_Roles.RoleName
  283. FROM dbo.aspnet_Roles, dbo.aspnet_UsersInRoles, dbo.aspnet_Users, dbo.aspnet_Applications
  284. WHERE dbo.aspnet_Roles.RoleId = dbo.aspnet_UsersInRoles.RoleId
  285. AND dbo.aspnet_Roles.ApplicationId = dbo.aspnet_Applications.ApplicationId
  286. AND dbo.aspnet_UsersInRoles.UserId = dbo.aspnet_Users.UserId
  287. AND dbo.aspnet_Users.LoweredUserName = LOWER(@UserName)
  288. AND dbo.aspnet_Users.ApplicationId = dbo.aspnet_Applications.ApplicationId
  289. AND dbo.aspnet_Applications.LoweredApplicationName = LOWER(@ApplicationName)
  290. ";
  291. InitConnection();
  292. bool closed = connection.State == ConnectionState.Closed;
  293. if (closed)
  294. connection.Open();
  295. DbCommand command = factory.CreateCommand ();
  296. command.CommandText = commandText;
  297. command.Connection = connection;
  298. command.CommandType = CommandType.Text;
  299. AddParameter (command, "UserName", username);
  300. AddParameter (command, "ApplicationName", ApplicationName);
  301. DbDataReader reader = command.ExecuteReader ();
  302. ArrayList roleList = new ArrayList();
  303. while (reader.Read())
  304. roleList.Add (reader.GetString(0));
  305. reader.Close();
  306. if (closed)
  307. connection.Close ();
  308. return (string[])roleList.ToArray(typeof (string));
  309. }
  310. public override string [] GetUsersInRole (string rolename)
  311. {
  312. string commandText = @"
  313. SELECT dbo.aspnet_Users.UserName
  314. FROM dbo.aspnet_Roles, dbo.aspnet_UsersInRoles, dbo.aspnet_Users, dbo.aspnet_Applications
  315. WHERE dbo.aspnet_Roles.RoleId = dbo.aspnet_UsersInRoles.RoleId
  316. AND dbo.aspnet_Roles.ApplicationId = dbo.aspnet_Applications.ApplicationId
  317. AND dbo.aspnet_UsersInRoles.UserId = dbo.aspnet_Users.UserId
  318. AND dbo.aspnet_Roles.LoweredRoleName = LOWER(@RoleName)
  319. AND dbo.aspnet_Users.ApplicationId = dbo.aspnet_Applications.ApplicationId
  320. AND dbo.aspnet_Applications.LoweredApplicationName = LOWER(@ApplicationName)
  321. ";
  322. InitConnection();
  323. bool closed = connection.State == ConnectionState.Closed;
  324. if (closed)
  325. connection.Open();
  326. DbCommand command = factory.CreateCommand ();
  327. command.CommandText = commandText;
  328. command.Connection = connection;
  329. command.CommandType = CommandType.Text;
  330. AddParameter (command, "RoleName", rolename);
  331. AddParameter (command, "ApplicationName", ApplicationName);
  332. DbDataReader reader = command.ExecuteReader ();
  333. ArrayList userList = new ArrayList();
  334. while (reader.Read())
  335. userList.Add (reader.GetString(0));
  336. reader.Close();
  337. if (closed)
  338. connection.Close ();
  339. return (string[])userList.ToArray(typeof (string));
  340. }
  341. [MonoTODO]
  342. public override void Initialize (string name, NameValueCollection config)
  343. {
  344. if (config == null)
  345. throw new ArgumentNullException ("config");
  346. base.Initialize (name, config);
  347. #if false
  348. ApplicationName = config["applicationName"];
  349. #else
  350. ApplicationName = "/";
  351. #endif
  352. string connectionStringName = config["connectionStringName"];
  353. string commandTimeout = config["commandTimeout"];
  354. if (applicationName.Length > 256)
  355. throw new ProviderException ("The ApplicationName attribute must be 256 characters long or less.");
  356. if (connectionStringName == null || connectionStringName.Length == 0)
  357. throw new ProviderException ("The ConnectionStringName attribute must be present and non-zero length.");
  358. // XXX check connectionStringName and commandTimeout
  359. connectionString = WebConfigurationManager.ConnectionStrings[connectionStringName];
  360. }
  361. public override bool IsUserInRole (string username, string rolename)
  362. {
  363. string commandText = @"
  364. SELECT COUNT(*)
  365. FROM dbo.aspnet_Users, dbo.aspnet_UsersInRoles, dbo.aspnet_Roles, dbo.aspnet_Applications
  366. WHERE dbo.aspnet_Roles.ApplicationId = dbo.aspnet_Applications.ApplicationId
  367. AND dbo.aspnet_Users.ApplicationId = dbo.aspnet_Applications.ApplicationId
  368. AND dbo.aspnet_UsersInRoles.RoleId = dbo.aspnet_Roles.RoleId
  369. AND dbo.aspnet_UsersInRoles.UserId = dbo.aspnet_Users.UserId
  370. AND dbo.aspnet_Applications.LoweredApplicationName = LOWER(@ApplicationName)
  371. AND dbo.aspnet_Roles.LoweredRoleName = LOWER(@RoleName)
  372. AND dbo.aspnet_Users.LoweredUserName = LOWER(@UserName)
  373. ";
  374. InitConnection();
  375. bool closed = connection.State == ConnectionState.Closed;
  376. if (closed)
  377. connection.Open();
  378. DbCommand command = factory.CreateCommand ();
  379. command.CommandText = commandText;
  380. command.Connection = connection;
  381. command.CommandType = CommandType.Text;
  382. AddParameter (command, "RoleName", rolename);
  383. AddParameter (command, "UserName", username);
  384. AddParameter (command, "ApplicationName", ApplicationName);
  385. bool rv = ((int)command.ExecuteScalar ()) != 0;
  386. if (closed)
  387. connection.Close ();
  388. return rv;
  389. }
  390. public override void RemoveUsersFromRoles (string [] usernames, string [] rolenames)
  391. {
  392. string commandText = @"
  393. DELETE dbo.aspnet_UsersInRoles
  394. FROM dbo.aspnet_UsersInRoles, dbo.aspnet_Users, dbo.aspnet_Roles, dbo.aspnet_Applications
  395. WHERE dbo.aspnet_UsersInRoles.UserId = dbo.aspnet_Users.UserId
  396. AND dbo.aspnet_UsersInRoles.RoleId = dbo.aspnet_Roles.RoleId
  397. AND dbo.aspnet_Roles.ApplicationId = dbo.aspnet_Applications.ApplicationId
  398. AND dbo.aspnet_Users.ApplicationId = dbo.aspnet_Applications.ApplicationId
  399. AND dbo.aspnet_Users.LoweredUserName = LOWER(@UserName)
  400. AND dbo.aspnet_Roles.LoweredRoleName = LOWER(@RoleName)
  401. AND dbo.aspnet_Applications.LoweredApplicationName = LOWER(@ApplicationName)";
  402. Hashtable h;
  403. h = new Hashtable();
  404. foreach (string u in usernames) {
  405. if (u == null)
  406. throw new ArgumentNullException ("null element in usernames array");
  407. if (h.ContainsKey (u))
  408. throw new ArgumentException ("duplicate element in usernames array");
  409. if (u.Length == 0 || u.Length > 256 || u.IndexOf (",") != -1)
  410. throw new ArgumentException ("element in usernames array in illegal format");
  411. h.Add (u, u);
  412. }
  413. h = new Hashtable();
  414. foreach (string r in usernames) {
  415. if (r == null)
  416. throw new ArgumentNullException ("null element in usernames array");
  417. if (h.ContainsKey (r))
  418. throw new ArgumentException ("duplicate element in usernames array");
  419. if (r.Length == 0 || r.Length > 256 || r.IndexOf (",") != -1)
  420. throw new ArgumentException ("element in usernames array in illegal format");
  421. h.Add (r, r);
  422. }
  423. InitConnection();
  424. bool closed = connection.State == ConnectionState.Closed;
  425. if (closed)
  426. connection.Open();
  427. DbTransaction trans = connection.BeginTransaction ();
  428. try {
  429. foreach (string username in usernames) {
  430. foreach (string rolename in rolenames) {
  431. DbCommand command = factory.CreateCommand ();
  432. command.Transaction = trans;
  433. command.CommandText = commandText;
  434. command.Connection = connection;
  435. command.CommandType = CommandType.Text;
  436. AddParameter (command, "UserName", username);
  437. AddParameter (command, "RoleName", rolename);
  438. AddParameter (command, "ApplicationName", ApplicationName);
  439. if (command.ExecuteNonQuery() != 1)
  440. throw new ProviderException (String.Format ("failed to remove users from role '{0}'.", rolename));
  441. }
  442. }
  443. trans.Commit ();
  444. }
  445. catch (Exception e) {
  446. trans.Rollback ();
  447. if (e is ProviderException)
  448. throw e;
  449. else
  450. throw new ProviderException ("", e);
  451. }
  452. finally {
  453. if (closed)
  454. connection.Close ();
  455. }
  456. }
  457. public override bool RoleExists (string rolename)
  458. {
  459. string commandText = @"
  460. SELECT COUNT(*)
  461. FROM dbo.aspnet_Roles, dbo.aspnet_Applications
  462. WHERE dbo.aspnet_Roles.ApplicationId = dbo.aspnet_Applications.ApplicationId
  463. AND dbo.aspnet_Applications.LoweredApplicationName = LOWER(@ApplicationName)
  464. AND dbo.aspnet_Roles.LoweredRoleName = LOWER(@RoleName)
  465. ";
  466. InitConnection();
  467. bool closed = connection.State == ConnectionState.Closed;
  468. if (closed)
  469. connection.Open();
  470. DbCommand command = factory.CreateCommand ();
  471. command.CommandText = commandText;
  472. command.Connection = connection;
  473. command.CommandType = CommandType.Text;
  474. AddParameter (command, "ApplicationName", ApplicationName);
  475. AddParameter (command, "RoleName", rolename);
  476. bool rv = ((int)command.ExecuteScalar ()) != 0;
  477. if (closed)
  478. connection.Close ();
  479. return rv;
  480. }
  481. [MonoTODO]
  482. public override string ApplicationName {
  483. get { return applicationName; }
  484. set {
  485. applicationName = value;
  486. }
  487. }
  488. }
  489. }
  490. #endif