我在Startup.cs中使用以下设置
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddAuthorization(options =>
{
options.AddPolicy("RequireCommericalRole", policy => policy.RequireRole("SG_Commercial"));
});
var appSettings = Configuration.GetSection("AppSettings");
services.Configure<AppSettings>(appSettings);
}
并在控制器中
[Authorize(Policy = "RequireCommericalRole")]
[Produces("application/json")]
public class AppSettingsController : Controller
{
private readonly AppSettings _appSettings;
public AppSettingsController(IOptions<AppSettings> appSettings)
{
_appSettings = appSettings.Value;
}
[HttpGet]
public IActionResult GetSettings()
{
var apiURL = _appSettings.API_URL;
return Ok(apiURL);
}
}
不适用于我的广告组设置。 Windows用户在正确的组中。
请告知