Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Henrik Sunesen 84 posts 281 karma points
    Sep 02, 2021 @ 13:52
    Henrik Sunesen
    0

    Umbraco Cloud + Hangfire

    Hello all,

    I'm having trouble to get Umbraco Cloud solution running with Hangfire.

    I followed the guide: https://cultiv.nl/blog/using-hangfire-for-scheduled-tasks-in-umbraco/

    But i'm getting an error when i try to run the solution:

    The OwinStartupAttribute.FriendlyName value 'UmbracoDefaultOwinStartup' does not match the given value 'UmbracoStandardOwinStartup' in Assembly 'Umbraco.Web, Version=8.0.0.0, Culture=neutral, PublicKeyToken=null'
    

    enter image description here

    I'm running on a local SQLExpress DB.

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Sep 02, 2021 @ 19:25
    Bjarne Fyrstenborg
    1

    Hi Henrik

    The owin startup class should look something like this:

    using MyProject.Core;
    using MyProject.Core.Filters;
    using Hangfire;
    using Hangfire.Server;
    using Hangfire.Storage;
    using Microsoft.AspNet.Identity;
    using Microsoft.Owin;
    using Microsoft.Owin.Security.Cookies;
    using Owin;
    using System;
    using Umbraco.Web;
    
    [assembly: OwinStartup(nameof(UmbracoStandardOwinStartup), typeof(UmbracoStandardOwinStartup))]
    namespace MyProject.Core
    {
        public class UmbracoStandardOwinStartup : UmbracoDefaultOwinStartup
        {
            public override void Configuration(IAppBuilder app)
            {
                // Ensure the default options are configured
                base.Configuration(app);
    
                app.UseCookieAuthentication(new CookieAuthenticationOptions
                {
                    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                    LoginPath = new PathString("/")
                });
    
                try
                {
                    var dashboardOptions = new DashboardOptions
                    {
                        // Only grant access to users in Umbraco with access to the Hangfire Section
                        Authorization = new[] { new UmbracoAuthorizationFilter() },
    
                        // Avoid showing back to site link
                        AppPath = null
                    };
    
                    app.UseHangfireDashboard("/hangfire", dashboardOptions);
                    app.UseHangfireServer();
    
                    // Run Hangfire jobs
                }
                catch (InvalidOperationException ex)
                {
                    // JobStorage.Current is not configured when installing updates
                    if (!ex.Message.StartsWith("JobStorage.Current"))
                        throw;
                }
            }
        }
    }
    

    ...

    using Hangfire.Annotations;
    using Hangfire.Dashboard;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Web;
    using Umbraco.Web.Composing;
    using Umbraco.Web.Security;
    
    namespace MyProject.Core.Filters
    {
        public class UmbracoAuthorizationFilter : IDashboardAuthorizationFilter
        {
            public bool Authorize([NotNull] DashboardContext context)
            {
                var http = new HttpContextWrapper(HttpContext.Current);
                var ticket = http.GetUmbracoAuthTicket();
                http.AuthenticateCurrentRequest(ticket, true);
    
                var user = Current.UmbracoContext.Security.CurrentUser;
    
                return user != null && user.Groups.Any(g => g.Alias == "admin");
            }
        }
    }
    

    Furthermore you need to ensure you have changed the default value of owin:appStartup key in web.config

    <appSettings>
         ...
         <add key="owin:appStartup" value="UmbracoStandardOwinStartup" />
    </appSettings>
    
  • Henrik Sunesen 84 posts 281 karma points
    Sep 03, 2021 @ 12:22
    Henrik Sunesen
    0

    Hi Bjarne,

    Thanks for the suggestion, i've tried to make it exactly like yours:

    Web.config:

         <add key="owin:appStartup" value="UmbracoStandardOwinStartup" />
    

    Folder structure: https://www.screencast.com/t/lhxLcrGuNjH

    But i still get the same error.

    I've installed these packages: https://www.screencast.com/t/ZjGkSl0Z5sW

    I hope someone can help me :)

  • Ranjit J. Vaity 66 posts 109 karma points
    Dec 03, 2022 @ 13:56
    Ranjit J. Vaity
    0

    Hi Henrik, I am not able to access these links anymore. can you repost these?

    Thanks, Ranjit

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Sep 03, 2021 @ 23:38
    Bjarne Fyrstenborg
    100

    It won't work placing the class files in App_Plugins folder.

    You need to either place these in App_Code folder to execute the code runtime, place the class files in a class library and compile the code into a dll. Typical a "Core" or "Library" project. Or in a web application project where is compiles the project.

  • Henrik Sunesen 84 posts 281 karma points
    Sep 07, 2021 @ 07:50
    Henrik Sunesen
    0

    Arrh of course, thank you so much!

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Sep 07, 2021 @ 11:01
    Bjarne Fyrstenborg
    0

    You are welcome.

    It would be great if you could mark the thread as solved :)

Please Sign in or register to post replies

Write your reply to:

Draft