在appsettings.json中
{
"MyArray": [
"str1",
"str2",
"str3"
]
}
Run Code Online (Sandbox Code Playgroud)
在Startup.cs中
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IConfiguration>(Configuration);
}
Run Code Online (Sandbox Code Playgroud)
在HomeController中
public class HomeController : Controller
{
private readonly IConfiguration _config;
public HomeController(IConfiguration config)
{
this._config = config;
}
public IActionResult Index()
{
return Json(_config.GetSection("MyArray"));
}
}
Run Code Online (Sandbox Code Playgroud)
上面有我的代码,我得到null如何获取数组?
下面的示例使用我从代码中获取的BackupDirectories列表填充ItemsControl.
如何更改此设置以便从app.config文件中获取相同的信息?
XAML:
<Window x:Class="TestReadMultipler2343.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"/>
<ColumnDefinition Width="160"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0"
Grid.Column="0"
Text="Title:"/>
<TextBlock
Grid.Row="0"
Grid.Column="1"
Text="{Binding Title}"/>
<TextBlock
Grid.Row="1"
Grid.Column="0"
Text="Backup Directories:"/>
<ItemsControl
Grid.Row="1"
Grid.Column="1"
ItemsSource="{Binding BackupDirectories}"/>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
后台代码:
using System.Collections.Generic;
using System.Windows;
using System.Configuration;
using System.ComponentModel;
namespace TestReadMultipler2343
{
public partial class Window1 : Window, INotifyPropertyChanged
{
#region ViewModelProperty: Title
private string _title;
public string Title
{
get …Run Code Online (Sandbox Code Playgroud) 我正在尝试根据 client_id 创建不同的登录页面。
用例:我的默认登录页面是经典的用户名/密码类型登录,但对于特定的 client_id,登录页面要求提供 3 个不同的信息,这些信息可以在他在邮件中收到的一张纸上找到(由第三方发送) )。一旦我有了这 3 个信息,我就可以验证并找到关联的用户。
技术:到目前为止,我已经做到了,一旦 IdentityServer4 将 /connect/authorize 重定向到它的默认登录路由 (/account/login),我就会根据 client_id 重定向到我的第二个登录。它可以工作,但一点也不优雅(感觉很hackish)。我确信有更好的方法来实现这一点,可能通过中间件直接从连接/授权重定向到我的第二个登录页面?
有什么想法/提示吗?