我在网上搜索,但有关的信息很少 ThreadHelper.JoinableTaskFactory.RunAsync
如果我有以下代码,请Test1
运行MainThread
:
public bool Test1()
{
// Do something here
ThreadHelper.JoinableTaskFactory.RunAsync(this.Test2);
// Do something else
return false;
}
private async Task Test2()
{
await TaskScheduler.Default;
// do something here
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
// do something here
}
Run Code Online (Sandbox Code Playgroud)
如果RunAsync
从未等待过可以吗?如果Test1
在Test2
运行完成之前返回会发生什么?
我想实现一个过滤器,在使用身份验证令牌身份验证 ( Bearer
)时跳过防伪令牌的验证。
在 ASP.NET Core 2.2 中,ValidateAntiforgeryTokenAuthorizationFilter
和 AutoValidateAntiforgeryTokenAuthorizationFilter
是公共的(即使位于Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
命名空间中),所以我能够从后者继承并ShouldValidate
轻松覆盖该方法。
在 ASP.NET Core 3.0 中,它们变成了内部的,因此不可能只从它们继承。我可以复制粘贴代码,但这显然不是理想的解决方案。
我在MSDN 的ASP.NET Core文章中关注了防止跨站点请求伪造 (XSRF/CSRF) 攻击,但它并没有真正提到与我的场景相关的任何内容。
DeployIfNotExists
我正在尝试根据现有策略创建策略AuditIfNotExists
。部署时不会出错,但会错误提示“没有相关资源与策略定义中的效果详细信息匹配”。当评估政策时。AuditIfnotExists
当我将其部署到同一管理组时,该策略确实运行良好。我想知道我是否错过了什么。
此策略用于创建删除 NSG 组(如果不存在)的警报。这是DeployIfNotExists
政策 - 你们觉得有什么问题吗?任何意见表示赞赏。谢谢。
{
"$schema":"https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion":"1.0.0.0",
"parameters":{
"effect":{
"type":"string",
"metadata":{
"displayName":"Effect",
"description":"Enable or disable the execution of the policy"
},
"allowedValues":[
"AuditIfNotExists",
"deployIfNotExists",
"Disabled"
],
"defaultValue":"deployIfNotExists"
}
},
"variables":{
"actionGroupName":"dsactiongroup"
},
"resources":[
{
"name":"CIS5.2.3-EnsureAuditDeleteNSG",
"type":"Microsoft.Authorization/policyDefinitions",
"apiVersion":"2019-09-01",
"properties":{
"policyType":"Custom",
"displayName":"CIS 5.2.3 Ensure that Activity Log Alert exists for Delete Network Security Group (Scored)",
"description":"Monitor Activity Alerts exist for specific activities.",
"mode":"all",
"metadata":{
"category":"Audit"
},
"parameters":{
},
"policyRule":{
"if":{
"allOf":[
{
"field":"type", …
Run Code Online (Sandbox Code Playgroud) 有没有一种巧妙的方法可以将 a 转换PSCustomObject
为自定义类作为 PowerShell 5.1 中的函数参数?自定义对象包含附加属性。
我希望能够做这样的事情:
class MyClass {
[ValidateNotNullOrEmpty()][string]$PropA
}
$input = [pscustomobject]@{
PropA = 'propA';
AdditionalProp = 'additionalProp';
}
function DuckTypingFtw {
[CmdletBinding()]
param(
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline)] [MyClass] $myObj
)
'Success!'
}
DuckTypingFtw $input
Run Code Online (Sandbox Code Playgroud)
不幸的是Success!
,我得到的不是:
DuckTypingFtw:无法处理参数“myObj”的参数转换。无法将值“@{PropA=propA;AdditionalProp=additionalProp}”转换为类型“MyClass”。错误:“无法转换”@{PropA=propA; “AdditionalProp=additionalProp}”
类型“System.Management.Automation.PSCustomObject”的值要键入“MyClass”。在 C:\temp\tmp.ps1:23 字符:15 + DuckTypingFtw $input + ~~~~~~ + CategoryInfo : InvalidData: (:) [DuckTypingFtw], ParameterBindingArgumentTransformationException + ExcellentQualifiedErrorId : ParameterArgumentTransformationError,DuckTypingFtw
如果我注释掉AdditionalProp
,一切正常。
基本上,我想要实现的目标是从一个函数返回一个对象并将其传递给第二个函数,同时确保第二个函数的参数具有所有预期的属性。
我想在构建服务器上运行一些 nUnit 测试,而不必在那里安装 .NET Core SDK。
测试目标netcoreapp3.1
.
对于 .NET Framework 可以使用 运行它们nunit-console-runner
,但对于 .NET Core 似乎不可能 - 请参阅/sf/answers/3699839391/。
如果发现这个问题https://github.com/Microsoft/vstest/issues/1224,但它似乎没有提供任何合理的解决方案。
VirtualBox 6.1.28 无法在 Windows 上启动盒子,并出现以下错误:
Failed to load R0 module C:\Program Files\Oracle\VirtualBox/VMMR0.r0:
SUP_IOCTL_LDR_OPEN failed (VERR_LDR_GENERAL_FAILURE).
Failed to load VMMR0.r0 (VERR_LDR_GENERAL_FAILURE).
Run Code Online (Sandbox Code Playgroud) .net ×1
.net-core ×1
asp.net-core ×1
asynchronous ×1
azure ×1
azure-policy ×1
c# ×1
csrf ×1
dotnet-test ×1
nunit ×1
powershell ×1
vagrant ×1
virtualbox ×1