在我们的应用程序中,我们有要在后台运行的Web API排队作业。我们使用HangFire进行作业的后台处理。Web API使用Windows身份验证。Hangfire服务器配置为作为Windows服务运行。
我正在尝试以将队列排队的同一用户的身份执行后台作业。
我尝试传递WindowsIdentity.GetCurrent()(由hangfire序列化并传递),引发的异常是“用于模拟的无效令牌-不能重复”
[HttpGet, Route("enq")]
public IHttpActionResult EnQueue(string country)
{
var curUser = System.Security.Principal.WindowsIdentity.GetCurrent();
var id = Hangfire.BackgroundJob.Enqueue(() => Services.Common.TestClass.Test(curUser , country));
return Ok(id);
}
遇到了一种调用WIN32 API方法登录用户的方法。但是由于将密码作为输入,因此不确定如何使用它。
以排队的同一用户身份执行后台作业的任何方法?
可能的解决方案:
https://blogs.msdn.microsoft.com/winsdk/2015/08/28/logon-as-a-user-without-a-password/
var upn = System.DirectoryServices.AccountManagement.UserPrincipal.Current.UserPrincipalName;
WindowsIdentity s4u = new WindowsIdentity(upn);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句