在中等信任托管上使用quartz.net

我需要在我的.NET MVC网站上安排调度function,而且我遇到了Quartz.net库,它可以完全满足我的需要。

问题是我在托管(GoDaddy)上运行我的网站,当我将Quartz.net 2.0.1添加到我的项目时,我得到"that assembly does not allow partially trusted callers"exception。 经过一些研究,我发现很多人都有同样的问题,有些人通过从Quartz.net中删除Common.Logging库来解决它。

我遵循了一些建议并删除了对Common.Logging的所有引用,但我仍然有问题。 它看起来还不够,现在我Inheritance security rules violated while overriding memberexception时Inheritance security rules violated while overriding memberInheritance security rules violated while overriding member ,更多细节:

 Inheritance security rules violated while overriding member: Quartz.Util.DirtyFlagMap`2.GetObjectData (System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden. 

看起来我真的需要在Quartz.net中更改某些内容才能使其正常工作。

有人在中等信任上运行Quartz.net吗? 如果是这样,需要做什么? 可能有人可以提出一些替代方案吗?

我建议自己构建Common.Logging,而不是从项目中删除它。 您可以从http://netcommon.sourceforge.net/downloads.html获取最新的来源。

我想第二个问题与C5.dll不受信任有关。 我也会自己构建它。 来源可以在这里找到: http : //www.itu.dk/research/c5/ 。

虽然除了构建dll之外还有其他选择(http://stackoverflow.com/questions/3072359/unblocking-a-dll-on-a-company-machine-how)我个人更喜欢自己构建dll,除非我绝对信任下载的产品。

斯坦纳尔的回答让我朝着正确的方向前进。 分享这里让QuartZNet在中等信任托管环境中工作的步骤。

QuartzNet最初遇到了中等信任的权限问题,我们需要执行以下操作来解决问题

(1)从github下载QuartzNet代码(2.1.0.400)并在对AssemblyInfo.cs进行以下更改后构建它

更换

 #if !NET_40 [assembly: System.Security.AllowPartiallyTrustedCallers] #endif 

 [assembly: AllowPartiallyTrustedCallers] #if NET_40 [assembly: SecurityRules(SecurityRuleSet.Level1)] #endif 

(2)下载C5代码(v 2.1)并用它构建

 [assembly: AllowPartiallyTrustedCallersAttribute() 

确保C5与Qartznet在同一.NET版本中编译。

(3)在TGH中的web.config中添加了石英部分,将requirepermission设置为false。 常见的日志记录部分也将requirepermission设置为false,并将其配置为使用Common.Logging.Simple.NoOpLoggerFactoryAdapter。

    

(4)使用namecollection作为参数的构造函数初始化调度程序,namecollection是从web.config中获取的石英部分。

在global.asax中

 QuartzScheduler.Start(); 

class级

 public class QuartzScheduler { public static void Start() { ISchedulerFactory schedulerFactory = new StdSchedulerFactory((NameValueCollection)ConfigurationManager.GetSection("quartz")); IScheduler scheduler = schedulerFactory.GetScheduler(); scheduler.Start(); IJobDetail inviteRequestProcessor = new JobDetailImpl("ProcessInviteRequest", null, typeof(InviteRequestJob)); IDailyTimeIntervalTrigger trigger = new DailyTimeIntervalTriggerImpl("Invite Request Trigger", Quartz.TimeOfDay.HourMinuteAndSecondOfDay(0, 0, 0), Quartz.TimeOfDay.HourMinuteAndSecondOfDay(23, 23, 59), Quartz.IntervalUnit.Second, 1); scheduler.ScheduleJob(inviteRequestProcessor, trigger); } } public class InviteRequestJob : IJob { public void Execute(IJobExecutionContext context) { RequestInvite.ProcessInviteRequests(); } }