Я переношу свое приложение из Asp.Net MVC 5 в Asp.Net Core 2.2. Как получить авторизованные заявки пользователей в Asp.Net Core 2.2?
Asp.Net MVC 5 код:
var identity = new ClaimsPrincipal(User).Claims; //returns 141 claims
Код Asp.Net Core 2.2:
var identity = User.Claims.ToArray(); //returns 75 claims for same user id
Я ожидаю, что приложение Asp.Net Core 2.2 вернет 141 претензию, но фактически возвращено 75 заявок.
---------------- Файл Startup.cs -----------------
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
//CSRF
services.AddAntiforgery(options => options.HeaderName = "X-XSRF-TOKEN");
//Below methods are default methods that came with Core template.
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
// In production, the Angular files will be served from this directory
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp/dist";
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IAntiforgery antiforgery)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.Use(async (context, next) =>
{
string path = context.Request.Path.Value;
if (path != null && !path.ToLower().Contains("/api"))
{
// XSRF-TOKEN used by angular in the $http if provided
var tokens = antiforgery.GetAndStoreTokens(context);
context.Response.Cookies.Append("XSRF-TOKEN",
tokens.RequestToken, new CookieOptions
{
HttpOnly = false,
Secure = true
}
);
}
await next();
});
app.UseSpaStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action=Index}/{id?}");
});
app.UseSpa(spa =>
{
// To learn more about options for serving an Angular SPA from ASP.NET Core,
// see https://go.microsoft.com/fwlink/?linkid=864501
spa.Options.SourcePath = "ClientApp";
if (env.IsDevelopment())
{
spa.Options.StartupTimeout = new System.TimeSpan(0, 0, 160);
spa.UseAngularCliServer(npmScript: "start");
}
});
}
}