.net-core

xunit - how to get HttpContext.User.Identity in unit tests

笑着哭i 提交于 2021-02-08 14:01:04
问题 I added a method to my controllers to get the user-id from the JWT token in the HttpContext . In my unit tests the HttpContext is null , so I get an exception. How can I solve the problem? Is there a way to moq the HttpContext ? Here is the method to get the user in my base controller protected string GetUserId() { if (HttpContext.User.Identity is ClaimsIdentity identity) { IEnumerable<Claim> claims = identity.Claims; return claims.ToList()[0].Value; } return ""; } One of my tests look like

Error “{”stateMachine“:{”<>1__state“:-2,”<>t__builder“:{” when run project netcore

给你一囗甜甜゛ 提交于 2021-02-08 13:48:12
问题 When I run project netcore I get a message {"stateMachine":{"<>1__state":-1,"<>t__builder":{ and I don't know how to fix this. I see error in command line Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1] An unhandled exception has occurred while executing the request. Newtonsoft.Json.JsonSerializationException: Self referencing loop detected for property 'task' with type 'System.Runtime.CompilerServices.AsyncTaskMethodBuilder` and Microsoft.AspNetCore.Server.Kestrel[13]

.NET Core environment variable returns null

你。 提交于 2021-02-08 13:22:15
问题 I have a .NET Core console application. I'm trying to retrieve the environment variable using the below code. var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); However, the variable "environment" always return null. I set the environment variable "ASPNETCORE_ENVIRONMENT" through Control Panel -> System Properties -> Environment Variables -> System Variables I also tried setting the environment variable using the command set ASPNETCORE_ENVIRONMENT=development ,

.NET Core environment variable returns null

我怕爱的太早我们不能终老 提交于 2021-02-08 13:22:12
问题 I have a .NET Core console application. I'm trying to retrieve the environment variable using the below code. var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); However, the variable "environment" always return null. I set the environment variable "ASPNETCORE_ENVIRONMENT" through Control Panel -> System Properties -> Environment Variables -> System Variables I also tried setting the environment variable using the command set ASPNETCORE_ENVIRONMENT=development ,

How to use MSBuild to build an existing .NET 4 project for .NET 5?

别等时光非礼了梦想. 提交于 2021-02-08 12:15:31
问题 Is it possible to msbuild a project that was created for .NET 4.x against the .NET 5 SDK without upgrading the project in VS? I have a .NET 4.7 library project that I compile for .NET 4.x using msbuild (and this issue is easily reproducible by creating a "Class Library (.NET Framework)" project for .NET 4.7). I want to build it for .NET 5, so I tried dotnet msbuild /property:TargetFrameworkVersion=net5.0 /property:TargetFrameworkIdentifier=.NETCoreApp Microsoft (R) Build Engine version 16.8.0

How to use MSBuild to build an existing .NET 4 project for .NET 5?

偶尔善良 提交于 2021-02-08 12:14:51
问题 Is it possible to msbuild a project that was created for .NET 4.x against the .NET 5 SDK without upgrading the project in VS? I have a .NET 4.7 library project that I compile for .NET 4.x using msbuild (and this issue is easily reproducible by creating a "Class Library (.NET Framework)" project for .NET 4.7). I want to build it for .NET 5, so I tried dotnet msbuild /property:TargetFrameworkVersion=net5.0 /property:TargetFrameworkIdentifier=.NETCoreApp Microsoft (R) Build Engine version 16.8.0

Setup OAuth2 JWT Token for ADFS and .Net Core

大兔子大兔子 提交于 2021-02-08 11:42:42
问题 Can someone explain the the OAuth2 JWT token generation and verification in .Net Core? 回答1: First You need to setup ADFS with a client id and redirect URL, then get a JWT token from ADFS server. See this post http://blog.scottlogic.com/2015/03/09/OAUTH2-Authentication-with-ADFS-3.0.html After that, if you are using .Net Core with JWT Bearer Token you need to export ADFS signing certificate using the following powershell commands: $certRefs=Get-AdfsCertificate -CertificateType Token-Signing

Setup OAuth2 JWT Token for ADFS and .Net Core

。_饼干妹妹 提交于 2021-02-08 11:42:05
问题 Can someone explain the the OAuth2 JWT token generation and verification in .Net Core? 回答1: First You need to setup ADFS with a client id and redirect URL, then get a JWT token from ADFS server. See this post http://blog.scottlogic.com/2015/03/09/OAUTH2-Authentication-with-ADFS-3.0.html After that, if you are using .Net Core with JWT Bearer Token you need to export ADFS signing certificate using the following powershell commands: $certRefs=Get-AdfsCertificate -CertificateType Token-Signing

Get the table name when configuring an entity

我的梦境 提交于 2021-02-08 11:38:02
问题 EF Core: I need to get the name of the table as the name of the entity, not dbset, also, I need the Id to be "tableName"+"Id" . I have a DbSet<Country> Countries - I need table name Country and Id column (inherited from base entity) to be CountryId . I started with this code that works: foreach (var entity in modelBuilder.Model.GetEntityTypes()) { var builderEntity = modelBuilder.Entity(entity.Name); // make table name to be entity name builderEntity.ToTable(entity.DisplayName()); // make Id

Get the table name when configuring an entity

孤街浪徒 提交于 2021-02-08 11:35:59
问题 EF Core: I need to get the name of the table as the name of the entity, not dbset, also, I need the Id to be "tableName"+"Id" . I have a DbSet<Country> Countries - I need table name Country and Id column (inherited from base entity) to be CountryId . I started with this code that works: foreach (var entity in modelBuilder.Model.GetEntityTypes()) { var builderEntity = modelBuilder.Entity(entity.Name); // make table name to be entity name builderEntity.ToTable(entity.DisplayName()); // make Id