1

在我们当前的Umbraco Cloud项目中,我们正在使用Hangfire库 (1.6.17) - 该库具有OWIN依赖项 (1.0.0)。

这是调用hangfire启动的代码:

在我们当前的项目中,我们正在使用 Hangfire 库 (1.6.17) - 该库具有 OWIN 依赖项 (1.0.0)。

这是调用hangfire启动的代码:

using Microsoft.Owin;
using Owin;
using Umbraco.Web;
using Hangfire;
using Hangfire.Dashboard;
using Hangfire.Annotations;
using Umbraco.Core.Models;
using Umbraco.Core;
using System.Web;

[assembly: OwinStartup(typeof(XX.Web.Core.Startup))]
namespace XX.Web.Core
{
    public class Startup : UmbracoDefaultOwinStartup
    {
        public override void Configuration(IAppBuilder app)
        {
            //ensure the default options are configured
            base.Configuration(app);

            var cs = Umbraco.Core.ApplicationContext.Current.DatabaseContext.ConnectionString;

            GlobalConfiguration.Configuration.UseSqlServerStorage(cs);

            app.UseHangfireDashboard("/umbraco/backoffice/hangfire", new DashboardOptions
            {
                Authorization = new[] { new UmbracoUserAuthorisedFilter() },
                AppPath = "/Umbraco"
            });

            app.UseHangfireServer();
        }
    }

    public class UmbracoUserAuthorisedFilter : IDashboardAuthorizationFilter
    {
        public bool Authorize([NotNull] DashboardContext context)
        {
            // In case you need an OWIN context, use the next line,
            // `OwinContext` class is the part of the `Microsoft.Owin` package.
            //var context = new OwinContext(owinEnvironment);

            // Allow all authenticated users to see the Dashboard (potentially dangerous).
            //return context.Authentication.User.Identity.IsAuthenticated;

            //this if you want to lock down to admins only
            var userService = ApplicationContext.Current.Services.UserService;
            var user = userService.GetByUsername(HttpContext.Current.User.Identity.Name);

            return user.IsAdmin();
            //this if you just want to make sure user is logged into backoffice
            //return UmbracoContext.Current.Security.CurrentUser != null;
        }
    }
}

这是能够使用该库的默认 hangfire 启动代码。该代码在 2 台本地机器(一个 Azure Web App 实例)上运行良好,但是当我将此代码推送到 Umbraco Cloud 分支时,出现以下错误:

无法加载文件或程序集“netstandard,Version=2.0.0.0,Culture=neutral,PublicKeyToken=cc7b13ffcd2ddd51”或其依赖项之一。该系统找不到指定的文件。

问题是:我们没有使用 .net 标准,两个项目(Web 和核心)都使用 .net 框架 4.6.2

这个问题有什么解决方法吗?

在此处输入图像描述

4

0 回答 0