VB.net help with AuthorizationFilter


I am hoping to get some help with the syntax for setting-up the dashboard authorization filters in VB.net.

I have this:

Public Sub Configuration(app As IAppBuilder)
       	GlobalConfiguration.Configuration.UseSqlServerStorage("Hangfire", New SqlServerStorageOptions With {.QueuePollInterval = TimeSpan.FromSeconds(1)})

       	Dim options As New DashboardOptions With {.AuthorizationFilters = New AuthorizationFilter With {.Users = "some_user", .Roles = "some_role"}}

       	app.UseHangfireDashboard("/hangfire", options)
End Sub

But it throws this error:

Unable to cast object of type ‘Hangfire.Dashboard.AuthorizationFilter’ to type ‘System.Collections.Generic.IEnumerable`1[Hangfire.Dashboard.IAuthorizationFilter]’.

Many thanks,


I’m not too familiar with VB.Net, but DashboardOptions.AuthorizationFilters is expecting an array of filters. You will need to create an array of the one item:

Dim options As New DashboardOptions
options.AuthorizationFilters = New IAuthorizationFilter() {
    New AuthorizationFilter With {.Users = "some_user", .Roles = "some_role"}

From the sounds of the variable names, the Users and Roles also need to be specified as arrays.

It should be noted that you will be removing the default authorisation filter which is usually added by the DashboardOptions constructor:

You can have both filters by adding them both to the array.

So I have setup an AuthorizationFilter with Hangfire using VB.net, here is the code I’m using to do this but obviously you can adapt it to your needs.

    Public Sub Configuration(app As IAppBuilder)
        ' Enable the application to use a cookie to store information for the signed in user
        Dim authorizationFilters = New List(Of AuthorizationFilter)
        authorizationFilters.Add(New AuthorizationFilter With {.Roles = "Admins"})
        Dim options = New DashboardOptions With {.AuthorizationFilters = authorizationFilters, .AppPath = "/App/Home"}
        app.UseHangfireDashboard("/hangfire", options)
    End Sub