I just had this same issue myself, I narrowed it down to some kind of weird routing issue and if I set the forms action to a valid view url it then posted to the surface controller quite happily
So for example I did this
@using (Html.BeginUmbracoForm<MembershipSurfaceController>("SubmitSigninForm", null, new { id = "submitsigninform", action = "/login"}, FormMethod.Post))
{
.....
}
Where "/login" is the actual view that hosts the viewcomponent
Hello everyone, I am having this same problem. What can I do please? This is the LoginController code:
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Umbraco.Cms.Core.Cache;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Core.Logging;
using Umbraco.Cms.Core.Routing;
using Umbraco.Cms.Core.Security;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Web;
using Umbraco.Cms.Infrastructure.Persistence;
using Umbraco.Cms.Web.Common.ActionsResults;
using Umbraco.Cms.Web.Common.Filters;
using Umbraco.Cms.Web.Common.Models;
using Umbraco.Cms.Web.Common.Security;
using Umbraco.Cms.Web.Website.Controllers;
using Umbraco.Extensions;
using SignInResult = Microsoft.AspNetCore.Identity.SignInResult;
namespace AmanaCard.Controllers
{
public class LoginController : SurfaceController
{
private readonly IMemberManager _memberManager;
private readonly IMemberSignInManager _signInManager;
private readonly ITwoFactorLoginService _twoFactorLoginService;
[ActivatorUtilitiesConstructor]
public LoginController(
IUmbracoContextAccessor umbracoContextAccessor,
IUmbracoDatabaseFactory databaseFactory,
ServiceContext services,
AppCaches appCaches,
IProfilingLogger profilingLogger,
IPublishedUrlProvider publishedUrlProvider,
IMemberSignInManager signInManager,
IMemberManager memberManager,
ITwoFactorLoginService twoFactorLoginService)
: base(umbracoContextAccessor, databaseFactory, services, appCaches, profilingLogger, publishedUrlProvider)
{
_signInManager = signInManager;
_memberManager = memberManager;
_twoFactorLoginService = twoFactorLoginService;
}
[HttpPost]
[ValidateAntiForgeryToken]
[ValidateUmbracoFormRouteString]
public async Task<IActionResult> HandleLogin([Bind(Prefix = "loginModel")] LoginModel model)
{
if (ModelState.IsValid == false)
{
return CurrentUmbracoPage();
}
MergeRouteValuesToModel(model);
// Sign the user in with username/password, this also gives a chance for developers to
// custom verify the credentials and auto-link user accounts with a custom IBackOfficePasswordChecker
SignInResult result = await _signInManager.PasswordSignInAsync(
model.Username, model.Password, model.RememberMe, true);
if (result.Succeeded)
{
TempData["LoginSuccess"] = true;
// If there is a specified path to redirect to then use it.
if (model.RedirectUrl.IsNullOrWhiteSpace() == false)
{
// Validate the redirect URL.
// If it's not a local URL we'll redirect to the root of the current site.
return Redirect(Url.IsLocalUrl(model.RedirectUrl)
? model.RedirectUrl
: CurrentPage!.AncestorOrSelf(1)!.Url(PublishedUrlProvider));
}
// Redirect to current URL by default.
// This is different from the current 'page' because when using Public Access the current page
// will be the login page, but the URL will be on the requested page so that's where we need
// to redirect too.
return RedirectToCurrentUmbracoUrl();
}
return CurrentUmbracoPage();
}
private void MergeRouteValuesToModel(LoginModel model)
{
if (RouteData.Values.TryGetValue(nameof(LoginModel.RedirectUrl), out var redirectUrl) && redirectUrl != null)
{
model.RedirectUrl = redirectUrl.ToString();
}
}
}
Umbraco 10: no service for type "MySurfaceController" has been registered
Calling surface controller action in component view as below:
Got the following error after submitting the form:
Stack info:
Any idea how to fix it? Thanks!
Hi May,
Can you show us the code of the controller ?
Dave
Hi Dave, here it is
I just had this same issue myself, I narrowed it down to some kind of weird routing issue and if I set the forms action to a valid view url it then posted to the surface controller quite happily
So for example I did this
Where "/login" is the actual view that hosts the viewcomponent
The original Umbraco 10 project was created from VisualStudio:
Create a new project -> Umbraco Project(Umbraco HQ)
I am able to resolve this issue by re-creating the solution/project from command line ( https://psw.codeshare.co.uk/):
dotnet new sln --name "MySolution" dotnet new umbraco --force -n "MyProject" --friendly-name "Administrator" --email "[email protected]" --password "1234567890" --development-database-type SQLite dotnet sln add "MyProject"
Thanks for all your helps!
Hello everyone, I am having this same problem. What can I do please? This is the LoginController code:
using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.Logging; using Umbraco.Cms.Core.Routing; using Umbraco.Cms.Core.Security; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Web; using Umbraco.Cms.Infrastructure.Persistence; using Umbraco.Cms.Web.Common.ActionsResults; using Umbraco.Cms.Web.Common.Filters; using Umbraco.Cms.Web.Common.Models; using Umbraco.Cms.Web.Common.Security; using Umbraco.Cms.Web.Website.Controllers; using Umbraco.Extensions; using SignInResult = Microsoft.AspNetCore.Identity.SignInResult;
namespace AmanaCard.Controllers { public class LoginController : SurfaceController {
}
I always got the same error if creating the project from VS umbraco 10 project.
Please try re-creating your project using the command below, and then add your controllers, etc. back.
dotnet new sln --name "MySolution" dotnet new umbraco --force -n "MyProject" --friendly-name "Administrator" --email "[email protected]" --password "1234567890" --development-database-type SQLite
dotnet sln add "MyProject"
is working on a reply...