Avoid Commas in FBA Roles and Members

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)

Figure 1 - Avoid Commas in FBA Role Members
Figure 1 - Avoid Commas in FBA Role Members

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.

BENNY AUSTIN

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s