public class ServiceModel { private readonly IHttpContextAccessor accessor; public ServiceModel(IHttpContextAccessor accessor) { this.accessor = accessor; } }
var user = accessor.HttpContext?.User
builder.Services.AddIdentity<AppUser, AppRole>(options => { options.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+/ "; options.User.RequireUniqueEmail = false; }) .AddEntityFrameworkStores<testContext>() .AddUserManager<UserManager<AppUser>>() .AddClaimsPrincipalFactory<ApplicationUserClaimsPrincipalFactory>() .AddDefaultTokenProviders(); builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { options.Cookie.Name = "MyAppCookie"; options.LoginPath = "/Account/Login"; }); builder.Services.AddHttpContextAccessor();
Microsoft.AspNetCore.Identity.EntityFrameworkCore Microsoft.EntityFrameworkCore Microsoft.AspNetCore.Mvc.ViewFeatures
User
null
accessor.HttpContext
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)