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'
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
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.
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:
I'm running on a local SQLExpress DB.
Hi Henrik
The owin startup class should look something like this:
...
Furthermore you need to ensure you have changed the default value of
owin:appStartup
key in web.configHi Bjarne,
Thanks for the suggestion, i've tried to make it exactly like yours:
Web.config:
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 :)
Hi Henrik, I am not able to access these links anymore. can you repost these?
Thanks, Ranjit
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.
Arrh of course, thank you so much!
You are welcome.
It would be great if you could mark the thread as solved :)
is working on a reply...