不知道我在这里缺少什么,但我无法从我的.net核心应用程序中的appsettings.json获取值.我的appsettings.json为:
{
"AppSettings": {
"Version": "One"
}
}
Run Code Online (Sandbox Code Playgroud)
启动:
public class Startup
{
private IConfigurationRoot _configuration;
public Startup(IHostingEnvironment env)
{
_configuration = new ConfigurationBuilder()
}
public void ConfigureServices(IServiceCollection services)
{
//Here I setup to read appsettings
services.Configure<AppSettings>(_configuration.GetSection("AppSettings"));
}
}
Run Code Online (Sandbox Code Playgroud)
模型:
public class AppSettings
{
public string Version{ get; set; }
}
Run Code Online (Sandbox Code Playgroud)
控制器:
public class HomeController : Controller
{
private readonly AppSettings _mySettings;
public HomeController(IOptions<AppSettings> settings)
{
//This is always null
_mySettings = settings.Value;
}
}
Run Code Online (Sandbox Code Playgroud)
_mySettings永远是空的.这里有什么我想念的吗?
我有一个应用程序登录时我想检查用户是否是特定AD组的一部分.如果是,则继续应用程序,如果没有则显示错误:"我确实有AD的LDAP连接地址".
我不知道我们怎么能做这个.NET核心,因为没有任何例子可以做到这一点.
c# active-directory asp.net-core-mvc asp.net-core asp.net-core-2.0
我的实体为:
public class User
{
public int Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我有我的UserViewModel作为
public class UserViewModel
{
public int Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我在控制器中如下使用这些:
//This is called from my view via ajax
public void Save(UserViewModel uv)
{
// this throws error: cannot convert from UserViewModel to Entity.User
MyRepository.UpdateUser(uv);
} …Run Code Online (Sandbox Code Playgroud) 我有一个使用 AWSDynamodDb 的 .NET Core 2.0 项目(您可以在此处忽略 dynamo db,因为问题与 dynamodDB 无关)
我有以下实体类:
[DynamoDBTable("TableName")]
public class MyData
{
[DynamoDBHashKey]
public string Id{ get; set; }
public string Name{ get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我想要的是“TableName”——传递给属性的值——从我的 appSettings.json 文件中填充。
{
"TableName": "NewTable"
}
Run Code Online (Sandbox Code Playgroud)
通过查看 appSettings 文件中的密钥,是否可以在运行时获得此值?
- 更新 -
我正在从我的控制器调用“MyData”类,如下所示:
var response = await context.ScanAsync<MyData>(conditions).GetRemainingAsync();
Run Code Online (Sandbox Code Playgroud)