Umbraco Membership, creating a login Screen. (13.2.2)
I'm encountering an issue with user authentication on my Umbraco website, running version 13.2.2. I'm attempting to create protected pages that require users to login, but despite configuring the login form and controller, authentication doesn't seem to be working as expected.
public class MemberController : SurfaceController
{
private readonly IMemberSignInManager _memberSignInManager;
public MemberController(IUmbracoContextAccessor umbracoContextAccessor,
IUmbracoDatabaseFactory databaseFactory,
ServiceContext services,
AppCaches appCaches,
IProfilingLogger profilingLogger,
IPublishedUrlProvider publishedUrlProvider,
IMemberSignInManager memberSignInManager)
: base(umbracoContextAccessor, databaseFactory, services, appCaches, profilingLogger, publishedUrlProvider)
{
_memberSignInManager = memberSignInManager;
}
[HttpPost]
public IActionResult HandleLogin(string username, string password)
{
if (ModelState.IsValid)
{
var result = _memberSignInManager.PasswordSignInAsync(username, password, false, false).Result;
if (result.Succeeded)
{
return Redirect("/vat-search/");
}
else
{
ViewBag.LoginError = "Invalid username or password";
return CurrentUmbracoPage();
}
}
return CurrentUmbracoPage();
}
}
When attempting to access protected pages, the login view is displayed as expected. However, upon submitting the login credentials, I'm redirected to:
/umbraco/surface/member/HandleLogin
Could anyone provide guidance on what additional steps might be necessary in terms of configuring Startup.cs or setting up a new route to ensure that user authentication works correctly?
Any insights or suggestions would be greatly appreciated. Thank you!
I’ll have to check when o get back to the office, but I’m pretty sure it’s not even getting to the controller, I think it’s something to do with routes, I’ll update this when I check properly with some break points.
Umbraco Membership, creating a login Screen. (13.2.2)
I'm encountering an issue with user authentication on my Umbraco website, running version 13.2.2. I'm attempting to create protected pages that require users to login, but despite configuring the login form and controller, authentication doesn't seem to be working as expected.
Here's the setup:
Login View (Login.cshtml):
Controller (MemberController.cs):
When attempting to access protected pages, the login view is displayed as expected. However, upon submitting the login credentials, I'm redirected to:
Could anyone provide guidance on what additional steps might be necessary in terms of configuring Startup.cs or setting up a new route to ensure that user authentication works correctly?
Any insights or suggestions would be greatly appreciated. Thank you!
if you debug your code, is the signin result succeeded?
I’ll have to check when o get back to the office, but I’m pretty sure it’s not even getting to the controller, I think it’s something to do with routes, I’ll update this when I check properly with some break points.
Thanks for your reply
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.