put in fixed error in appsetting.cs does not have other key

This commit is contained in:
2026-05-13 18:22:17 +10:00
parent fb751ecbc3
commit c0bc89083d
5 changed files with 46 additions and 38 deletions
+12 -3
View File
@@ -24,9 +24,18 @@ services.AddEndpointsApiExplorer();
services.AddSwaggerGen();
var appSettingsSection = builder.Configuration.GetSection("AppSettings");
services.Configure<AppSettings>(appSettingsSection);
var appSettings = appSettingsSection.Get<AppSettings>();
var key = Encoding.ASCII.GetBytes(appSettings.Secret);
string skey = "";
if (appSettingsSection == null)
{
skey = builder.Configuration.GetValue<string>("AppSettings:SecretKey");
}
else
{
services.Configure<AppSettings>(appSettingsSection);
var appSettings = appSettingsSection.Get<AppSettings>();
skey = appSettings.Secret;
}
var key = Encoding.ASCII.GetBytes(skey);
services.AddAuthentication(x =>
{