WebMatrix - SimpleMembershipProvider Class
-
I've just been looking at the source for this and discovered this method. Not the best code I've seen and was wondering what others thought?
public override void AddUsersToRoles(string\[\] usernames, string\[\] roleNames) { if (!InitializeCalled) { PreviousProvider.AddUsersToRoles(usernames, roleNames); } else { using (var db = ConnectToDatabase()) { long userCount = usernames.Length; long roleCount = roleNames.Length; List userIds = GetUserIdsFromNames(db, usernames); List roleIds = GetRoleIdsFromNames(db, roleNames); // Generate a INSERT INTO for each userid/rowid combination, where userIds are the first params, and roleIds follow for (int uId = 0; uId < userCount; uId++) { for (int rId = 0; rId < roleCount; rId++) { if (IsUserInRole(usernames\[uId\], roleNames\[rId\])) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "WebDataResources.SimpleRoleProvder\_UserAlreadyInRole", usernames\[uId\], roleNames\[rId\])); } // REVIEW: is there a way to batch up these inserts? long rows = db.Execute("INSERT INTO " + UsersInRoleTableName + " (UserId, RoleId) VALUES (" + userIds\[uId\] + "," + roleIds\[rId\] + "); "); if (rows != 1) { throw new ProviderException("WebDataResources.Security\_DbFailure"); } } } } } }
Jammer
-
I've just been looking at the source for this and discovered this method. Not the best code I've seen and was wondering what others thought?
public override void AddUsersToRoles(string\[\] usernames, string\[\] roleNames) { if (!InitializeCalled) { PreviousProvider.AddUsersToRoles(usernames, roleNames); } else { using (var db = ConnectToDatabase()) { long userCount = usernames.Length; long roleCount = roleNames.Length; List userIds = GetUserIdsFromNames(db, usernames); List roleIds = GetRoleIdsFromNames(db, roleNames); // Generate a INSERT INTO for each userid/rowid combination, where userIds are the first params, and roleIds follow for (int uId = 0; uId < userCount; uId++) { for (int rId = 0; rId < roleCount; rId++) { if (IsUserInRole(usernames\[uId\], roleNames\[rId\])) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "WebDataResources.SimpleRoleProvder\_UserAlreadyInRole", usernames\[uId\], roleNames\[rId\])); } // REVIEW: is there a way to batch up these inserts? long rows = db.Execute("INSERT INTO " + UsersInRoleTableName + " (UserId, RoleId) VALUES (" + userIds\[uId\] + "," + roleIds\[rId\] + "); "); if (rows != 1) { throw new ProviderException("WebDataResources.Security\_DbFailure"); } } } } } }
Jammer
-
I've just been looking at the source for this and discovered this method. Not the best code I've seen and was wondering what others thought?
public override void AddUsersToRoles(string\[\] usernames, string\[\] roleNames) { if (!InitializeCalled) { PreviousProvider.AddUsersToRoles(usernames, roleNames); } else { using (var db = ConnectToDatabase()) { long userCount = usernames.Length; long roleCount = roleNames.Length; List userIds = GetUserIdsFromNames(db, usernames); List roleIds = GetRoleIdsFromNames(db, roleNames); // Generate a INSERT INTO for each userid/rowid combination, where userIds are the first params, and roleIds follow for (int uId = 0; uId < userCount; uId++) { for (int rId = 0; rId < roleCount; rId++) { if (IsUserInRole(usernames\[uId\], roleNames\[rId\])) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "WebDataResources.SimpleRoleProvder\_UserAlreadyInRole", usernames\[uId\], roleNames\[rId\])); } // REVIEW: is there a way to batch up these inserts? long rows = db.Execute("INSERT INTO " + UsersInRoleTableName + " (UserId, RoleId) VALUES (" + userIds\[uId\] + "," + roleIds\[rId\] + "); "); if (rows != 1) { throw new ProviderException("WebDataResources.Security\_DbFailure"); } } } } } }
Jammer
I want to know what led you to posting this in the SB, an article writer, obviously experienced in using CP and you post code into the one area where people can legitimately be rude about it (a more gentle attitude now exists in the Lounge). Consider yourself thoroughly chastised, ridiculed and insulted, back to the c# forum with you I say!
Never underestimate the power of human stupidity RAH
-
I want to know what led you to posting this in the SB, an article writer, obviously experienced in using CP and you post code into the one area where people can legitimately be rude about it (a more gentle attitude now exists in the Lounge). Consider yourself thoroughly chastised, ridiculed and insulted, back to the c# forum with you I say!
Never underestimate the power of human stupidity RAH
strange thing, i was on "the weird and wonderful", clicked on the link to the first page and ended up on the soapbox, maybe the same happened to him?
I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p) "Given the chance I'd rather work smart than work hard." - PHS241 "'Sophisticated platform' typically means 'I have no idea how it works.'"
-
strange thing, i was on "the weird and wonderful", clicked on the link to the first page and ended up on the soapbox, maybe the same happened to him?
I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p) "Given the chance I'd rather work smart than work hard." - PHS241 "'Sophisticated platform' typically means 'I have no idea how it works.'"
-
I could not reproduce, so i didn't report it. Must be some company police getting in the way, i can't even open CP on IE here, as the forums expand all posts and all ajax is replace by normal posts, so i'll blame this weirdness on company police as well.
I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p) "Given the chance I'd rather work smart than work hard." - PHS241 "'Sophisticated platform' typically means 'I have no idea how it works.'"
-
I could not reproduce, so i didn't report it. Must be some company police getting in the way, i can't even open CP on IE here, as the forums expand all posts and all ajax is replace by normal posts, so i'll blame this weirdness on company police as well.
I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p) "Given the chance I'd rather work smart than work hard." - PHS241 "'Sophisticated platform' typically means 'I have no idea how it works.'"
-
I've just been looking at the source for this and discovered this method. Not the best code I've seen and was wondering what others thought?
public override void AddUsersToRoles(string\[\] usernames, string\[\] roleNames) { if (!InitializeCalled) { PreviousProvider.AddUsersToRoles(usernames, roleNames); } else { using (var db = ConnectToDatabase()) { long userCount = usernames.Length; long roleCount = roleNames.Length; List userIds = GetUserIdsFromNames(db, usernames); List roleIds = GetRoleIdsFromNames(db, roleNames); // Generate a INSERT INTO for each userid/rowid combination, where userIds are the first params, and roleIds follow for (int uId = 0; uId < userCount; uId++) { for (int rId = 0; rId < roleCount; rId++) { if (IsUserInRole(usernames\[uId\], roleNames\[rId\])) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "WebDataResources.SimpleRoleProvder\_UserAlreadyInRole", usernames\[uId\], roleNames\[rId\])); } // REVIEW: is there a way to batch up these inserts? long rows = db.Execute("INSERT INTO " + UsersInRoleTableName + " (UserId, RoleId) VALUES (" + userIds\[uId\] + "," + roleIds\[rId\] + "); "); if (rows != 1) { throw new ProviderException("WebDataResources.Security\_DbFailure"); } } } } } }
Jammer
It's the The Soapbox baby.. ;)
-
I want to know what led you to posting this in the SB, an article writer, obviously experienced in using CP and you post code into the one area where people can legitimately be rude about it (a more gentle attitude now exists in the Lounge). Consider yourself thoroughly chastised, ridiculed and insulted, back to the c# forum with you I say!
Never underestimate the power of human stupidity RAH
I was thinking it more of a soapbox thing as I'm not asking a programming question about the code. I don't want to ask any programming questions about the code. I'm just amazed at how botched an inefficient the code is in places. Scores of people will be using the MebMatrix code in their projects and some of it really is of questionable quality. You're right I am an experienced CP person which is why it didn't feel appropriate to post this in the C# form since I have no overtly programming related question about the code. Sorry.
Jammer
-
Jammer wrote:
and was wondering what others thought?
I think you missed that bit in bold red letters at the top of this page.
Use the best guess
-
I was looking for the coding horrors forum to be honest ... I couldn't find it anymore ...
Jammer
-
It's the next one down in the TreeView on the left[^].
Use the best guess
-
I want to know what led you to posting this in the SB, an article writer, obviously experienced in using CP and you post code into the one area where people can legitimately be rude about it (a more gentle attitude now exists in the Lounge). Consider yourself thoroughly chastised, ridiculed and insulted, back to the c# forum with you I say!
Never underestimate the power of human stupidity RAH