I'm trying to implement claims authentication in to my site I have followed the tutorial shown here
Replacing Forms Authentication now from what I can see I have done everything correctly... so I thought, when I run my application enter my credentials I then try to set the Claim as shown here
[HttpPost]
public ActionResult Register(UserRegister userRegister)
{
if (ModelState.IsValid)
{
var userProfile = new RegisterService().RegisterUser(userRegister);
if (userProfile != null)
{
var userCredentials = new[] {
new Claim("UserId", Convert.ToString(userProfile.UserId)),
new Claim("UniqueId", Convert.ToString(userProfile.UniqueId)),
new Claim("Username", Convert.ToString(userProfile.Username)),
new Claim("Firstname", Convert.ToString(userProfile.Firstname)),
new Claim("Surname", Convert.ToString(userProfile.Surname)),
new Claim("Email", Convert.ToString(userProfile.EmailAddress))};
var id = new ClaimsIdentity(userCredentials, "Forms");
var cp = new ClaimsPrincipal(id);
var token = new SessionSecurityToken(cp);
var sam = FederatedAuthentication.SessionAuthenticationModule;
sam.WriteSessionTokenToCookie(token);
return RedirectToAction("UserProfile", "Profile", new { area = "Profile" });
}
else
{
TempData["error"] = "Something went wrong with your registration, plese check the details you entered and try again";
}
}
return View(userRegister);
}
But the Error I get is Object reference not set to an instance of an object. on the following line of the above
sam.WriteSessionTokenToCookie(token);
I'm not sure what exactly I'm doing wrong here, reason behind this is because I have another project again with claims authentication implemented successfully.
Any help would be beneficial.
Thanks