When implementing Form Based Authentication (FBA) for SharePoint sites, ensure that your role members and role names do not have commas in them. A comma in any role member attribute or in role name, throws “Error: Access Denied” exception. (Figure 1)
This exception is difficult to trace because the debugger runs through your custom code without reporting any exception and then the SharePoint services throw this exception. Since FBA data, is usually sourced from custom databases the data could easily contain commas for e.g. Last name, First name. I would replace commas (or for that matter any other special character) in any attribute BEFORE assigning them to role member. A simple Regex() statement would do the trick, as shown in the code snippet below:
Dim user As MembershipUser Dim userCol As New MembershipUserCollection Dim regex As Regex = New Regex("[^ \w]") Dim uname As String = regex.Replace(rs("UserName").ToString(), "") ' Create the membership user... user = New MembershipUser(Membership.Provider.Name, uname,...other parms) ' Add the user to the membership user collection userCol.Add(user)
That would save a lot of troubleshooting time.