能否在Azure App Service应用设置中存储ASP.NET Core的IdentityConfig配置?
Absolutely! You can store that IdentityConfig setting in Azure App Service's Application Settings, and it’s actually a recommended practice for managing environment-specific configurations without having to tweak your appsettings.json or code across different deployments. Here’s how to do it:
Step 1: Add the setting in the Azure Portal
- Navigate to your Azure App Service resource, then go to Configuration > Application settings
- Click New application setting to create a new entry
- For the Name, use the hierarchical colon syntax that ASP.NET Core recognizes:
IdentityConfig:Authority - For the Value, input your authority URL:
http://myapp.azurewebsites.net - If you use deployment slots, check the Deployment slot setting box to keep slot-specific values separate (optional but handy)
- Don’t forget to click Save to apply the changes
Step 2: Access the setting in your ASP.NET Core app
ASP.NET Core automatically integrates with Azure App Service’s configuration system, pulling in these settings and overriding any matching values from your local appsettings.json. You can use it just like you would with local config:
First, define a configuration class (if you haven’t already):
public class IdentityConfig { public string Authority { get; set; } }
Then bind it in your Program.cs:
builder.Services.Configure<IdentityConfig>(builder.Configuration.GetSection("IdentityConfig"));
Whenever you need the Authority value, inject IOptions<IdentityConfig> into your service or controller:
private readonly IdentityConfig _identityConfig; public YourController(IOptions<IdentityConfig> identityConfig) { _identityConfig = identityConfig.Value; } // Usage example var authorityUrl = _identityConfig.Authority;
Key Notes
- Precedence: Azure Application Settings take priority over values in
appsettings.json, so your environment-specific URL will always be used at runtime - Restart Required: After adding or updating the setting, you’ll need to restart your App Service for the new configuration to take effect
- Hierarchical Support: The colon (
:) syntax perfectly maps to nested JSON structures, so this approach works for any complex config you want to externalize
内容的提问来源于stack exchange,提问作者Damith

