Sunday, February 27, 2011

Custom login webpart SharePoint 2010 FBA Claims Internal 500 error Signout

Reference
http://blogs.msdn.com/b/jjameson/archive/2011/02/25/claims-login-web-part-for-sharepoint-server-2010.aspx

Steps
1. Configure FBA (web.config, web application settings) on SP 2010 farm

2. Create a VS 2010 SP Visual webpart

3. Add asp:login control.
" OnAuthenticate="AuthenticateUser"
runat="server" >

4. OnAuthenticate event handler,

string membershipProvider = "aspnetmembershipprovider";
string roleProvider = "aspnetroleprovider";

e.Authenticated = SPClaimsUtility.AuthenticateFormsUser(
new Uri(SPContext.Current.Web.Url),
LoginControl.UserName,
LoginControl.Password);

if (!e.Authenticated) return;

SecurityToken secTk = SPSecurityContext.SecurityTokenForFormsAuthentication(webUri, membershipProvider, roleProvider, LoginControl.UserName, LoginControl.Password);
if (secTk == null)
{

e.Authenticated = false;
return;
}
else
{

SPFederationAuthenticationModule fam = SPFederationAuthenticationModule.Current;
fam.SetPrincipalAndWriteSessionToken(secTk);
e.Authenticated = true;

SPUtility.Redirect(SPContext.Current.Web.Url,SPRedirectFlags.Trusted , this.Context);

}

5. Deploy code.

6. Add webpart to content page.

7. Set content page as default login page under web application authentication settings for FBA

8. Make sure webapplication and site collection have annonymous turned ON.

9. Test by navigating to home page of site collection. It should auto-redirect to content page with login webpart.

10.Test login with aspnetdb user login and password information.

6. Once user is logged in, click ootb Signout button and no INTERNAL 500 ERROR should occur, it should successfully navigate to login content page.

Post comments if you have questions.

No comments:

Post a Comment