如何appsettings.json
使用获取数据Microsoft.Extensions.Configuration
?我的 JSON 在下面,但此代码不起作用。一般来说,我的愿望是得到一个数组或列表。但我无法实现它。
var someArray = configuration.GetSection("Test").GetChildren().Select(x => x).ToArray();
Run Code Online (Sandbox Code Playgroud)
var someArray = configuration.GetSection("Test").GetChildren().Select(x => x).ToArray();
Run Code Online (Sandbox Code Playgroud) 请告诉我为什么这段代码不起作用.
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(options =>
{
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultSignInScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(options =>
{
options.RequireHttpsMetadata = false;
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidIssuer = AuthOptions.ISSUER,
ValidateAudience = true,
ValidAudience = AuthOptions.AUDIENCE,
ValidateLifetime …
Run Code Online (Sandbox Code Playgroud) 我使用 ASP.NET Core 2.1 和 JwtBearer 方案进行身份验证,如下所示:
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(o =>
{
// my options here
});
}
Run Code Online (Sandbox Code Playgroud)
非常标准,但是我遇到的问题是我的令牌权限发现端点需要授权才能访问。我需要做的是将基本身份验证标头注入到 JWT 中间件对我的权限端点执行的请求中。我正在查看配置选项,但没有看到任何允许我执行此操作的内容。我还在查看源代码,看看是否可以看到 http 请求是在哪里发出的,但它通过抽象和扩展方法非常混乱,我还没有找到它。
有人能告诉我是否可以在某个地方设置它,或者我是否必须创建自己的授权处理程序并手动将它们绑定在一起?任何建议表示赞赏。
我有and和IQueryable<int>
and 在较早的处理阶段IQueryable<int?>
使用a从中删除了空值Where()
。我现在希望UNION()
在两个可查询对象之间执行a ,但是因为一个是可空类型,而另一个则不能。
我该如何解决?
我的代码:
distance = ['0.12', '0.02', '0.13', '0.02', '0.13', '0.02', '0.13', '0.02', '0.12', '0.01', '0.13', '0.02', '0.12', '0.02', '0.12', '0.02', '0.13', '0.02', '0.13', '0.02', '0.12', '0.02', '0.13', '0.02', '0.13', '0.02', '0.13', '0.02', '0.13', '0.02', '0.13', '0.02', '0.13', '0.02', '0.13', '0.01', '0.13', '0.02', '0.13', '0.01']
Run Code Online (Sandbox Code Playgroud)
值来自CSV文件并将其附加到距离列表.如何将它们相加以便我可以获得总距离?我已尝试在网站上给出的一些答案,但他们没有工作:(
我试图了解如何使用IEnumerator接口及其用途.我有一个实现IEnumerator接口的类.字符串数组传递给构造函数方法.
问题是当我执行代码时,数组未正确列出.应该做的顺序"ali"
,"veli"
,"hatca"
但它在这个顺序控制台上市"veli"
,"hatca"
和-1
.我感到很困惑.我在这做错了什么?你能帮忙吗?
static void Main(string[] args)
{
ogr o = new ogr();
while (o.MoveNext())
{
Console.WriteLine(o.Current.ToString());
}
}
public class ogr: IEnumerator
{
ArrayList array_ = new ArrayList();
string[] names = new string[] {
"ali", "veli", "hatca"
};
public ogr()
{
array_.AddRange(names);
}
public void addOgr(string name)
{
array_.Add(name);
}
int position;
public object Current
{
get
{
if (position >= 0 && position < array_.Count)
{
return …
Run Code Online (Sandbox Code Playgroud) 我正在制作一个程序,如果用户输入文本,它会将任何大写字母转换为小写:
def lowerChar(char):
if ord(char) >= 65 and ord(char) <= 90:
char = int(ord(char)) + 32
char = (chr(char))
return print(char)
else:
return print(char)
def lowerString(string):
x = len(string)
for i in range(x):
char = string[0 + i]
lowerChar(char)
result = ""
result = result + lowerChar(string[i])
string = input("type")
lowerString(string)
Run Code Online (Sandbox Code Playgroud)
错误是:
Traceback (most recent call last):
File "C:\Python34\njn.py", line 24, in <module>
lowerString(string)
File "C:\Python34\njn.py", line 19, in lowerString
result = result + lowerChar(string[i])
TypeError: Can't convert 'NoneType' object …
Run Code Online (Sandbox Code Playgroud) c# ×5
asp.net-core ×3
jwt ×2
python ×2
.net ×1
.net-core ×1
iqueryable ×1
json ×1
linq ×1
list ×1
nullable ×1
python-3.x ×1
sum ×1