これは、我々が何をすべきかです:
は、私たちは、それぞれの環境ごとに異なるappSettings.json
ファイルを持っています。

すべてのファイルがIdentityServer用に別の値が含まれています。例えば
{
"IdentityServerSettings": {
"Authority": "http://localhost:5000",
"ApiName": "tb5api"
}
}
その後Startup.csクラスで、我々は現在の環境に基づいて設定JSONファイルをロードします。そして、あなたが必要な場所IdentityServerSettings
あなたが設定方法コントローラにORでそれらを注入することができ
/// <summary>
/// This class is a representation of the configuration of the API for Identity Server
/// </summary>
public class IdentityServerSettings
{
// Authority is the Identity Server URL
public string Authority { get; set; }
// Current API/Resource Name
public string ApiName { get; set; }
}
:
private readonly IHostingEnvironment _env;
public IConfigurationRoot Configuration { get; }
public Startup(IHostingEnvironment env)
{
_env = env;
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
public void ConfigureServices(IServiceCollection services)
{
services.Configure<IdentityServerSettings>(Configuration.GetSection("IdentityServerSettings"));
......
はその後、我々はに私達の設定をロードするクラスを持っている
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
#region Identity Server Config
var identityServerOptions = app.ApplicationServices.GetService<IOptions<IdentityServerSettings>>().Value;
// Setup Identity Server Options for this API -
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
{
Authority = identityServerOptions.Authority,
RequireHttpsMetadata = false,
ApiName = identityServerOptions.ApiName,
NameClaimType = "username",
});
.......
この場合、Env.IsStaging()とEnv.IsProduction()は十分ではありませんか? –
@DanNguyen私はブールインラインに基づいてURLをハードコードしたくありません。私は彼らがいくつかの設定ファイルや環境変数を介して読み込まれるべきだと思います。 – Bob