I had a VS 2017 ASP.NET Core 2.2 Project and I wanted to start a new project based on the same code.
I created a new project and copied in the main code. I then reinstalled the NuGet packages (same versions) and checked that all the configs were the same. I renamed the namespace to be the same as the project.
In startup.cs:
services.AddAuthentication(IISDefaults.AuthenticationScheme);services.AddAuthorization(options =>{options.AddPolicy("GroupOne", policy =>policy.Requirements.Add(new GroupRequirement(new string [] { Environment.GetEnvironmentVariable("GROUP")})));});services.AddTransient<IClaimsTransformation, CustomClaimsTransformer>();
Transformer - if I set a breakpoint in here it never gets hit:
using MyProject.MyManagement;using Microsoft.AspNetCore.Authentication;using System.Linq;using System.Security.Claims;using System.Threading.Tasks;
namespace MyProject.Test{public class CustomClaimsTransformer : IClaimsTransformation{public Task<ClaimsPrincipal> TransformAsync(ClaimsPrincipal principal){var identity = principal.Identities.FirstOrDefault(x => x.IsAuthenticated);if (identity == null) return Task.FromResult(principal);
var user = identity.Name;if (user == null) return Task.FromResult(principal);
((ClaimsIdentity)principal.Identity).AddClaim(new Claim("Code", TestManagement.GetCode(user)));return Task.FromResult(principal);}}}
The only error I get on the webpage is that the claim doesn't exist.
VS Output: Exception thrown: 'System.InvalidOperationException' in System.Linq.dll
Chrome:Failed to load resource: the server responded with a status of 500 (Internal Server Error)
Setting a breakpoint in the claims transformer doesn't seem to do anything.
Renaming the namespace in the old project works fine, so the main difference is that I manually reinstalled the dependences using NuGet. I have gone through every config and property menu and they seem identical.
I have no idea how to get better errors?