I have created a custom web part that let's the user sign in using their windows accounts. However, the I get Object Not Set to the Reference error when I set the SetPrincipalAndWriteSessionToken. Here is the code:
// Get Token
var stoken = SPFormsUserNameSecurityTokenHandler.CreateSecurityToken(WindowsMembershipProvider, WindowsRoleProvider, username, password);
if (stoken != null)
{
// Sign User In
SPFederationAuthenticationModule fam = SPFederationAuthenticationModule.Current;
fam.SetPrincipalAndWriteSessionToken(stoken);
}
The WindowsMembershipProvider is "i", from the Web.Config and WindowsRoleProvider is "c" from the web.config. If I remove the roleprovider, it says "Value cannot be null", even though it is not a required parameter.
Can someone please help me out?
Thanks!