Hangfire dashboard returns 404
Asked Answered
T

6

8

When trying to access the hangfire dashboard on my local IIS at domain/hangfire/ I get a 404 response. This is in a webforms project targeting .Net 4.5.1, Hangfire is version 1.5.3. My startup and authorisationoverride classes are as follows:

[assembly: OwinStartup(typeof(MyNamespace.Startup))]
namespace MyNamespace
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            GlobalConfiguration.Configuration.UseSqlServerStorage("MyConnString");

            DashboardOptions opts = new DashboardOptions
            {
                AuthorizationFilters = new[] { new AuthorisationOverride() }
            };

            app.UseHangfireServer();
            app.UseHangfireDashboard("/hangfire", opts);
        }
    }
}

public class AuthorisationOverride : Hangfire.Dashboard.IAuthorizationFilter
{
    public bool Authorize(IDictionary<string, object> owinEnvironment)
    {
        return true;
    }
}

Jobs are running successfully, but I've run out of ideas for getting the Dashboard to work.

Tripe answered 29/12, 2015 at 11:50 Comment(4)
Which version of hangfire are you using?Unceremonious
1.5.3, have updated the question accordingly.Tripe
Did you manage to solve this? I'm having the same problem after deploying to a different server.Aboveboard
We didn't. we're running without the dashboard for now and have a backlog item to investigate and maybe add a parallel that just runs the dashboard connected to the same database.Tripe
G
14

I had something similar but I managed to get it resolved by reading through this post.

Hope you will have a better luck following through that if you haven't yet. The main problem for me was the missing DLL, and then the removing site data from the TemporaryASP.NET folder.

Edit: Someone down voted this answer because I used a link for the solution.

Since I did find a solution to this specific problem, I thought I will give it another try to share. :)

Here are the steps that I have taken to come to a solution.

  1. Confirm you have the Microsoft.Owin.Host.SystemWeb.dll in your bin directory of this project. (In my case, the dll was missing)
  2. Stop your app pool
  3. Navigate to your TemporaryASP.NET folder : C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files and delete the folder inside of your site/application's folder.
  4. Restart you app pool
  5. Navigate to "/admin" or whatever you set your dashboard url to be "/hangfire" by default.
Glorify answered 8/3, 2016 at 20:1 Comment(1)
Appreciate your tenacity =)Kweichow
E
9

Struggled with this for a few hours today and just fixed it in my project.

Try moving your Hangfire configuration code higher up in your Startup class's Configuration method.

I had my Hangfire configuration code at the very bottom of Startup.Configuration and just happened to discover that the dashboard works again when I move it before some of the other OWIN stuff I was configuring.

Specifically, I moved it above the following code in my project:

app.UseCors(CorsOptions.AllowAll);

app.MapSignalR();

AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
RouteConfig.RegisterRoutes(RouteTable.Routes);

// my AutoMapper configuration

// some async/await code that was calling .Wait() here. 

I didn't take time to figure out exactly which line of code was breaking the Hangfire dashboard, but I hope that helps someone.

Also for the record, the old code was working under IIS Express at https://localhost:44342/hangfire. I was getting the 404 in full IIS at https://localhost/appname/hangfire.

Ecospecies answered 21/2, 2017 at 19:58 Comment(1)
This solved things for me. Apparently the Hangfire dashboard configuration needs to be called before any calls to app.UseEndpoints(.....)Colan
T
3

Add this line in your web.config file:

<system.webServer>
    <handlers>
    <add name="hangfireDashboard" path="hangfire" type="System.Web.DefaultHttpHandler" verb="*" />
    </handlers>
</system.webServer>
Theatheaceous answered 11/4, 2017 at 7:28 Comment(3)
It cause this error for me: The DefaultHttpHandler.BeginProcessRequest method is not supported by IIS integrated pipeline mode.Disadvantageous
This fixed it for me!Sworn
Now it is broken, with the same message as the one RAM is reporting. Did you manage to fix it RAM? If you can shed any light i would be really happy!Sworn
D
2

Since there is no solution so far, I would like to share something that I rectified to get this issue resolved.

If you're facing this issue only in production then, your web.config file is not properly configured.

Firstly, assuming you have already created the Startup class, add the following to the web.config under :

<add key="owin:AutomaticAppStartup" value="true" />

Next, make sure that you have referenced the OWIN assemblies as the below following:

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>

Although, when you install OWIN via nuget, the setup will automatically update the web.config for you, but just in case it doesn't, you can always add this. Further make sure this above OWIN version matches with the one yo have installed via nuget.

Hope this helps somebody!

Edit: Answering the OP's original question, Hangfire returns 404 error when it is not started. Apart from adding the Startup OWIN class, we need to mention automaticstartup=true in the web config also. The next issue IIS will look for is reference to Hangfire, where is we kick in the assembly details.

Dutchman answered 25/9, 2017 at 7:48 Comment(0)
T
1

application Startup

 [assembly: OwinStartupAttribute(typeof(yournamespace.Startup))]
    namespace yournamespace    
    public partial class Startup
            {
                public void Configuration(IAppBuilder app)
                {

                    var storage = new SqlServerStorage("connectionstring");

                    ......
                    ......
                    app.UseHangfireDashboard("/Scheduler", new DashboardOptions() { AuthorizationFilters = new[] { new HangFireAuthorizationFilter() } }, storage);
                }

Authorization Filter

public class HangFireAuthorizationFilter:IAuthorizationFilter
    {
        public bool Authorize(IDictionary<string, object> owinEnvironment)
        {
            // In case you need an OWIN context, use the next line.
            // `OwinContext` class is defined in the `Microsoft.Owin` package.
            var context = new OwinContext(owinEnvironment);

            return context.Authentication.User.Identity.IsAuthenticated &&
                   context.Authentication.User.IsInRole("xyz");

        }

    }

You Can Ignore the HangFireAuthorizationFilter if you want to.

Timberwork answered 30/3, 2016 at 15:4 Comment(0)
O
0

The problem for me was missing ASP.NET installation on the server

Obstinacy answered 23/1, 2021 at 13:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.