How can I automatically sign a User in after registering. I am posting the registration with Ajax because I'm adding more fields to the register view model and on the response, I want to sign the just registered user in.
You should provide more details , are you using something like ASP.NET Membership Provider /ASP.NET Identity to authenticate or are you writing your own custom authentication layer?
If you are using MVC & Asp.net Identity , i would suggest modify the `Register.cshtml` to include more fields and also `RegisterViewModel` , after user register his account , he will be login by default :
if (result.Succeeded)
{
await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
// For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
// Send an email with this link
// string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
// var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
// await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
return RedirectToAction("Index", "Home");
}
Best Regards,
Nan Yu
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue.
Member
4 Points
14 Posts
Log Users in after registration and posting with Ajax
Feb 01, 2019 05:26 PM|Samseen|LINK
Hi Guys,
How can I automatically sign a User in after registering. I am posting the registration with Ajax because I'm adding more fields to the register view model and on the response, I want to sign the just registered user in.
All-Star
18265 Points
3594 Posts
Microsoft
Re: Log Users in after registration and posting with Ajax
Feb 04, 2019 02:07 AM|Nan Yu|LINK
Hi Samseen ,
You should provide more details , are you using something like ASP.NET Membership Provider /ASP.NET Identity to authenticate or are you writing your own custom authentication layer?
If you are using MVC & Asp.net Identity , i would suggest modify the `Register.cshtml` to include more fields and also `RegisterViewModel` , after user register his account , he will be login by default :
Best Regards,
Nan Yu
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue.