404 page not found Core Controller конструктор не работает и остальное

Всем привет, помогите пожалуйста разобраться - вот startup.cs

    public class Startup
    {
        public IConfiguration Configuration { get; }

        public Startup(IConfiguration configuration)
        {
            this.Configuration = configuration;
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {

            //добавляет контроллеры как зависимости
            services.AddControllers();
            services.AddRazorPages();

            var authOptionConfiguration = Configuration.GetSection("Auth");

            //регистрирует данную конфигурацию в контроллерах как зависимость
            services.Configure<AuthOptions>(authOptionConfiguration);
            services.AddMvc();

            services.AddCors(options =>
            options.AddDefaultPolicy(
                builder =>
                {
                    builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader();

                })

            );
;
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseCors();

            app.UseHttpsRedirection();
            app.UseRouting();
            app.UseAuthorization();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });


            app.UseStatusCodePages();
            app.UseStaticFiles();
        }
    }

А это код самого контроллера класса:

    [ApiController]
    [Route("api/[controller]")]
    public class AuthController : ControllerBase
    {
        private readonly IOptions<AuthOptions> authOptions;
        public AuthController(IOptions<AuthOptions> authOptions)
        {
            this.authOptions = authOptions;
        }

        private List<Account> Accounts => new List<Account>
        {

            new Account()
            {
                Id = Guid.Parse("6DC42CF2-637D-45B1-9CFF-271859151B8B"),
                Email = "[email protected]",
                Password = "user",
                Roles = new Role[]{Role.User}
            },
            new Account()
            {
                Id = Guid.Parse("669DDDD8-3803-4E92-BC08-EBA80DEF35A9"),
                Email = "[email protected]",
                Password = "user2",
                Roles = new Role[]{Role.User}
            },
            new Account()
            {
                Id = Guid.Parse("9E0170A7-47CC-4FA3-B7D8-6059E0980B70"),
                Email = "[email protected]",
                Password = "admin",
                Roles = new Role[]{Role.Admin}
            }
        };

        [Route("login")]
        [HttpPost("login")]
        [Produces("application/json")]
        public IActionResult Login([FromBody] Login request)
        {
            var user = AuthenticateUser(request.Email, request.Password);
            if (user != null)
            {
                //Generate JWT
                var token = GenerateJWT(user);

                return Ok(
                    new
                    {
                        access_token = token
                    }
                    );
            }

            return Unathorized();

        }

        private IActionResult Unathorized()
        {
            throw new NotImplementedException();
        }

        private Account AuthenticateUser(string email, string password)
        {
            return Accounts.SingleOrDefault(zx => zx.Email == email && zx.Password == password);
        }

        private string GenerateJWT(Account user)
        {
            //Header
            var authParams = authOptions.Value;

            var securityKey = authParams.GetSymmetricSecurityKey();
            var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);
            //Header

            //PayLoad
            var claims = new List<Claim>
            {
                new Claim(JwtRegisteredClaimNames.Email, user.Email),
                new Claim(JwtRegisteredClaimNames.Sub, user.Id.ToString())
            };

            foreach (var role in user.Roles)
            {
                claims.Add(new Claim("role", role.ToString()));
            }

            var token = new JwtSecurityToken(authParams.Issuer,
                authParams.Audience,
                claims,
                expires: DateTime.Now.AddSeconds(authParams.TokenLifetime),
                signingCredentials: credentials);


            return new JwtSecurityTokenHandler().WriteToken(token);
        }
    }

По факту получаю 404 Page Not Found

Status Code: 404; Not Found


Ответы (0 шт):