- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在使用 HostingEnvironment.QueueBackgroundWorkItem
在 ASP.Net 应用程序的后台运行工作,基于 Scott Hanselman 的博客文章 How to run Background Tasks in ASP.NET .
我想以当前用户身份运行后台任务。我已尝试传递 WindowsPrincipal 并在操作中设置 Thread.CurrentPrincipal,但这并没有导致操作以当前用户身份执行。
这是否可能,或者使用 HostingEnvironment 是否总是意味着以应用程序池身份运行?
编辑
与我原来的问题不完全一致,但我也尝试通过 CallContext.LogicalSetData() 和 CallContext.LogicalGetData() 传递一个值。在 Get 端,该值始终为 null。
编辑 #2
还在排队端试过这个:
using (HostingEnvironment.Impersonate(windowsIdentity.Token))
{
HostingEnvironment.QueueBackgroundWorkItem(work);
}
当真正完成工作时,Action中当前的WindowsIdentity仍然是app pool identity。
最佳答案
您“必须”使用“HostingEnvironment”的任何具体原因?
或者您尝试过使用 WindowsImpersonationContext 吗?
System.Security.Principal.WindowsImpersonationContext impersonationContext;
impersonationContext =
((System.Security.Principal.WindowsIdentity)User.Identity).Impersonate();
//Insert your code that runs under the security context of the authenticating user here.
impersonationContext.Undo();
您可以了解更多操作方法 here
关于c# - 将 QueueBackgroundWorkItem 与用户身份一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31125971/
我们正在运行 ASP.NET WebAPI 2 服务,我们希望使用我们的记录器将一些请求记录到电子邮件/数据库中。 因为它是后台工作,而且因为在 asp.net 中,我认为我们应该使用 Hosting
我读过 Stephen's article关于 Asp.net 中的 fire and forget 后台操作。 不建议使用 Task.Run 进行即发即弃,因为 Asp.net 不知道您已将任务排队
我有一个 wep api,每秒收到超过 100 个请求,并且需要快速回复。 每个请求中有两个主要工作: 从缓存中获取答案并将其返回给用户 将结果发送到事件中心(进行一些每小时计算) API 调用者对第
我们正在使用 HostingEnvironment.QueueBackgroundWorkItem 对长时间运行的后台任务进行排队。这很好用,但是,当事务超时时,我们没有得到任何异常并且线程似乎被杀死
我读过 this documentation其中表示使用 HostingEnvironment.QueueBackgroundWorkItem 运行操作: Differs from a normal
在 ASP.NET QueueBackgroundWorkItem 方法中使用 async 有什么好处? HostingEnvironment.QueueBackgroundWorkItem(asyn
我正在使用 HostingEnvironment.QueueBackgroundWorkItem 在 ASP.Net 应用程序的后台运行工作,基于 Scott Hanselman 的博客文章 How
我有一个方法使用HostingEnvironment.QueueBackgroundWorkItem 我希望在此调用之前对某些行为进行单元测试,但是,测试因 System.InvalidOperati
有没有办法取消使用 HostingEnvironment.QueueBackgroundWorkItem 制作的后台任务? ? 有CancellationToken它会通知任务是否被取消,但我该怎么做
我需要在 ASP.NET WebAPI 中生成一些长时间运行的任务,我选择使用 QueueBackgroundWorkItem 来实现。 我的问题是 - 我需要为这些任务实现一个 WhenAll 机制
我尝试在 azure 辅助角色上使用 HostingEnviornment.QueueBackgroundWorkItem 在后台执行某些任务,但我在代码中遇到异常“由于当前状态,操作无效对象。”.
我们正在使用 .NET Core Web Api,并寻找一种轻量级解决方案来将具有可变强度的请求记录到数据库中,但不希望客户端等待保存过程。 不幸的是,dnx 中没有实现 HostingEnviron
我的理解是引入了 HostingEnvironment.QueueBackgroundWorkItem API,因此可以在 Asp.net 应用程序中生成一个新线程,并且当 AppDomain 发出关
我发现了一个不错的小工具,它已添加到 v4.5.2 中的 ASP.NET 我想知道它有多安全,以及如何在 ASP.NET MVC 或 Web API 场景中有效地利用它。 我知道我一直想在我的 Web
我正在编写一个自定义记录器,用于通过网络将日志从 Azure Functions 写入到目标。该记录器需要是“即发即忘”异步的——等待每个日志写入会太慢。但是,我不希望每次主机关闭时最后几个日志条目都
目前我正在使用 HostingEnvironment.RegisterObject 在我的 MVC 5 应用程序中运行我的后台工作。具体来说,我有, public class BackgroundWo
我有一个 ASP.Net 应用程序,其中使用 HostingEnvironment.QueueBackgroundWorkItem 运行后台任务,如下面的代码所示。 问题:下面代码中安排的后台任务是使
我有一个 Web 应用程序,它通过 QueueBackgroundWorkItem 在后台执行一些处理。 我正在为应用程序中的功能连接单元测试,当它尝试调用它时,我收到以下错误: System.Inv
使用到底有什么区别 Task.Run(() => { LongRunningMethod(); }); 或 HostingEnvironment.QueueBackgroundWorkIte
在“System.Web”ASP.NET中,后台工作可以通过RegisterObject注册/QueueBackgroundWorkItem为了参与 IIS 的关闭序列(完整的 90 秒宽限期),但我
我是一名优秀的程序员,十分优秀!