我有应用程序,我必须使用一个证书,需要一个来自提示窗口的引脚.
我有以下代码.
SecureString password = GetPassword();
X509Certificate2 certificate = GetCertificate();
var cspParameters = new CspParameters(1,
"ProviderName",
"KeyContainerName",
null,
password);
certificate.PrivateKey = new RSACryptoServiceProvider(cspParameters);
Run Code Online (Sandbox Code Playgroud)
在控制台应用程序中一切正常,但是当我在Windows服务或从任务调度程序启动的控制台应用程序中运行该代码时,应用程序在该行上冻结.
certificate.PrivateKey = new RSACryptoServiceProvider(cspParameters);
Run Code Online (Sandbox Code Playgroud)
没有例外,没有进展.
我正在使用与应用程序相同的凭据运行Windows服务.
Windows 10/Windows Server 2012
你有什么想法有什么不对吗?
我有带有自定义策略和授权处理程序的 Web API。我想重用授权处理程序,但是当在信号器的集线器上使用属性时 HttpContext 为空。
例如,这是我的控制器。
[Authorize]
public sealed class ChatsController : ControllerBase
{
[HttpPost("{chatId}/messages/send")]
[Authorize(Policy = PolicyNames.ChatParticipant)]
public Task SendMessage() => Task.CompletedTask;
}
Run Code Online (Sandbox Code Playgroud)
这是我的授权处理程序。我可以从 HttpContext 中提取“chatId”,然后使用我的自定义逻辑来授权用户。
internal sealed class ChatParticipantRequirementHandler : AuthorizationHandler<ChatParticipantRequirement>
{
private readonly IHttpContextAccessor _httpContextAccessor;
public ChatParticipantRequirementHandler(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, ChatParticipantRequirement requirement)
{
if(_httpContextAccessor.HttpContext != null)
{
// Logic
}
return Task.CompletedTask;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,这不适用于 Azure SignalR,因为我无权访问 HttpContext。我知道我可以提供自定义 IUserIdProvider,但我不知道如何从我的自定义授权处理程序中的“Join”方法访问“chatId”。
[Authorize]
public sealed class ChatHub : Hub<IChatClient>
{
[Authorize(Policy = …Run Code Online (Sandbox Code Playgroud)