相关疑难解决方法(0)

ASP.NET core 3.1:ConfigureAppConfiguration 是否与 launchSettings.json 交互?

使用 kestrel 从 Visual Studio 2019 启动 ASP.NET core 3.1 Web 应用程序时,我遇到了奇怪的行为(我的意思是不使用IIS Express 的启动配置文件)。

我创建了一个最小的应用程序来重现该问题。

操作系统:Windows 10(内部版本 19041.746) Visual Studio 版本:Visual Studio 2019 版本 16.8.4

这是 csproj 文件:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>


</Project>
Run Code Online (Sandbox Code Playgroud)

这是 launchSettings.json 文件:

{
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:52222",
      "sslPort": 0
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "weatherforecast",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "TestWebApplication": {
      "commandName": "Project",
      "launchBrowser": …
Run Code Online (Sandbox Code Playgroud)

c# .net-core kestrel-http-server asp.net-core asp.net-core-3.1

5
推荐指数
1
解决办法
2576
查看次数

如何在 ASP.NET Core 6 中创建构建器之前读取 IConfiguration

我正在使用以这种方式创建构建器的库

var webApiOptions = new AkaAppOptions<ApiOptions>(ApplicationId, authenticationType);
var builder = new AkaAppBuilder<ApiOptions>(args, webApiOptions);
Run Code Online (Sandbox Code Playgroud)

现在这个构建器包含IConfiguration我需要的。

我的问题是我需要阅读配置才能知道authenticationType它是什么类型。这发生在我有一个WebApplicationBuilder.

我的选择是创建临时的WebApplicationBuilder,读取配置,然后创建这个库生成器,我猜这里的缺点是内存。

另一种选择是手动读取appsettings.json以获取该信息/缺点是内存和内存环境应用程序设置?

读哪一篇

例如,我会做这样的事情来创建临时构建器,而不是我需要的构建器

var tempBuilder = WebApplication.CreateBuilder(args);
var useExternalAuth = tempBuilder.Configuration.GetSection("ExternalAuth").Exists();
var authenticationType = useExternalAuth ? AuthenticationType.ExternalService : AuthenticationType.Service;

var webApiOptions = new AkaAppOptions<ApiOptions>(ApplicationId, authenticationType);
var builder = new AkaAppBuilder<ApiOptions>(args, webApiOptions);
Run Code Online (Sandbox Code Playgroud)

还有其他选择吗?

c# .net-core asp.net-core asp.net-core-6.0

0
推荐指数
1
解决办法
1118
查看次数