admin管理员组文章数量:1191725
I have a .NET 8 Blazor solution. In the server project, I added some Minimal APIs protected with individual accounts (just using the Visual Studio template).
For example:
public static void MapClientEndpoints (this IEndpointRouteBuilder routes)
{
var group = routes.MapGroup("/api/Client").WithTags(nameof(Client));
group.MapGet("/", async (HypnoContext db) =>
{
return await db.Client.ToListAsync();
})
.RequireAuthorization()
.WithName("GetAllClients")
.WithOpenApi();
}
Also, in the server side, I configure the IHttpClientFactory
like this:
builder.Services
.AddScoped(sp => sp
.GetRequiredService<IHttpClientFactory>()
.CreateClient("ServerAPI"))
.AddHttpClient("ServerAPI", (provider, client) =>
{
#if DEBUG
client.BaseAddress = new Uri("https://localhost:7241");
#else
client.BaseAddress = new Uri("https://myrealurl");
#endif
});
In the client project, I added the same configuration for IHttpClientFactory
. If I call from a page the API via HttpClient
, the call successfully retrieves the data.
Now, I want to use different configuration for each environment. For this reason, I created different appsettings files (appsettings.Development.json
, appsettings.Production.json
, ...).
To load those settings, I added this code:
IHostbuilder.Environmentuilder.Environment;
builder.Configuration
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", true, true);
Adding this code, the calls to the APIs are not authenticated any more. In the appsettings.json
, there is no configuration for the IHttpClientFactory
.
What can I do to fix this issue?
本文标签: cMinimal API with Individual Accounts and read appconfigStack Overflow
版权声明:本文标题:c# - Minimal API with Individual Accounts and read appconfig - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738457141a2087820.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论