I'm trying to call a method in one of my surface controllers from hangfire. But i'm getting a "Object reference not set to an instance of an object." exception.
As far as I can read the problem is, that controllers is not made for this.
But what is the right way, if I need to have access to Contentservice in a method, that needs to work as a hangfire cronjob?
An example:
public void DoSomething()
{
//Creating instance of the surface controller
MailController mail = new MailController();
RecurringJob.AddOrUpdate(() => mail.SendCSV("test"), Cron.Minutely);
}
OwinStartup Class:
public class UmbracoStandardOwinStartup : UmbracoDefaultOwinStartup
{
public override void Configuration(IAppBuilder app)
{
//ensure the default options are configured
base.Configuration(app);
// Configure hangfire
var options = new SqlServerStorageOptions { PrepareSchemaIfNecessary = true };
const string umbracoConnectionName = Umbraco.Core.Constants.System.UmbracoConnectionName;
var connectionString = System.Configuration
.ConfigurationManager
.ConnectionStrings[umbracoConnectionName]
.ConnectionString;
GlobalConfiguration.Configuration
.UseSqlServerStorage(connectionString, options);
// Give hangfire a URL and start the server
app.UseHangfireDashboard("/hangfire");
app.UseHangfireServer();
var scheduler = new ScheduleHangfireJobs();
scheduler.DoSomething();
}
}
Hi, to consume an umbraco content from third party applications, you need to build a UmbracoApiController (API) which is similar to surface controller (MVC).
Call method in Surface controller from hangfire
Hello all,
I'm trying to call a method in one of my surface controllers from hangfire. But i'm getting a "Object reference not set to an instance of an object." exception.
As far as I can read the problem is, that controllers is not made for this.
But what is the right way, if I need to have access to Contentservice in a method, that needs to work as a hangfire cronjob?
An example:
OwinStartup Class:
Hi, to consume an umbraco content from third party applications, you need to build a UmbracoApiController (API) which is similar to surface controller (MVC).
https://our.umbraco.com/Documentation/Reference/Routing/WebApi
Hi Walter,
Thank you, that helped me so much!
is working on a reply...