我的AngularJs代码:
var Customer = '<%=ConfigurationSettings.AppSettings["CusID"]%>';
alert(Customer);
Web配置代码:
<configuration><appSettings><add key='CusID' value='POKA' /></appSettings></configuration>
我想从我的角度js控制器获取Web配置应用程序设置值。任何人都可以帮助我。
谢谢
创建服务以读取设置,
using AngularClient.ViewModel;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
namespace AngularClient.Controllers
{
[Route("api/[controller]")]
public class ClientAppSettingsController : Controller
{
private readonly ClientAppSettings _clientAppSettings;
public ClientAppSettingsController(IOptions<ClientAppSettings> clientAppSettings)
{
_clientAppSettings = clientAppSettings.Value;
}
[HttpGet]
public IActionResult Get()
{
return Ok(_clientAppSettings);
}
}
}
然后调用该服务来获取值。
configClient() {
// console.log('window.location', window.location);
// console.log('window.location.href', window.location.href);
// console.log('window.location.origin', window.location.origin);
return this.http.get(window.location.origin + window.location.pathname + '/api/ClientAppSettings').map(res => {
this.clientConfiguration = res.json();
});
}