[Route("/Account/Login")]
public async Task<IActionResult> LoginAsync()
{
var claims = new List<Claim>
{
new Claim(ClaimTypes.Name, "Gianni"),
};
var identity = new ClaimsIdentity(claims,
CookieAuthenticationDefaults.AuthenticationScheme);
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity), new AuthenticationProperties { IsPersistent = true});
return Redirect("/");
}
What am I doing wrong or what could be causing this issue?
Below is some example code that should help you get started:
Add AddUserCookieAuthentication(cookieName: "MyAuthCookie") after AddComposers and before Build() in ConfigureServices (Startup.cs). The code to make this method available is below.
Also add these lines to app.UseUmbraco().WithMiddleware..
Hello, you showed us how to add the authentication cookie, within the Configure method, but as I saw, when I put a debugger on it, it does not come to the break point. I understood from this link: https://cornehoskam.com/posts/umbraco-8-versus-9-dependency-injection, that startup.cs is not accessible, unless we write it as a class that implements Composer.
Like this:
using IOCDocs.NotificationHandlers;
using IOCDocs.Services;
using Microsoft.Extensions.DependencyInjection;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Core.Notifications;
namespace IOCDocs
{
public class MyComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.AddNotificationHandler<ContentTypeSavedNotification, ContentTypeSavedHandler>();
builder.Services.AddSingleton<IFooBar, Foobar>();
}
}
}
My question is, is there a similar way to add the authentication cookie in this manner? of Composers?
CookieAuthentication not working in website
CookieAuthentication seems not to be working as expected in my Umbraco 10 project. I'm using Umbraco 10.1.0.
It seems to be creating the Authentication Cookie but User.Identity.Name is always NULL.
I added this line to ConfigureServices:
and I added these lines to the Configure method:
This is the code from within my Login action:
What am I doing wrong or what could be causing this issue?
Hello, I just came up with the same issue. Did you maybe find a solution to this problem?
I'm also curious about a solution. Facing the same issue 🤔 Any news?
Below is some example code that should help you get started:
Add
AddUserCookieAuthentication(cookieName: "MyAuthCookie")
after AddComposers and before Build() in ConfigureServices (Startup.cs). The code to make this method available is below.Also add these lines to app.UseUmbraco().WithMiddleware..
Middleware..
https://stackoverflow.com/questions/55128952/user-identity-name-is-null-in-cookie-authentication-in-net-core
Hello, you showed us how to add the authentication cookie, within the Configure method, but as I saw, when I put a debugger on it, it does not come to the break point. I understood from this link: https://cornehoskam.com/posts/umbraco-8-versus-9-dependency-injection, that startup.cs is not accessible, unless we write it as a class that implements Composer. Like this:
My question is, is there a similar way to add the authentication cookie in this manner? of Composers?
Thanks!!
is working on a reply...