我在我的 ASP.net 核心应用程序中使用 hangfire 来运行一些后台任务。我正在使用 IIS,我已将 Hangfire 配置如下:
using Hangfire;
namespace Whm.APIPortal
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddHangfire(option =>
{
option.UseSqlServerStorage(Configuration.GetConnectionString("HangFireConnection"));
});
services.AddHangfireServer();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
app.UseHangfireDashboard();
app.UseHangfireServer();
}
}
}
下面是我的 appsettings.json 文件
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"ConnectionStrings": {
"DefaultConnection": "Server=.\\SQLEXPRESS;Database=Whm;User Id=sa;Password=***;MultipleActiveResultSets=true",
"HangFireConnection": "Server=.\\SQLEXPRESS;Database=WhmHangFire;User Id=sa;Password=***;"
},
"AllowedHosts": "*"
}
每当我尝试启动应用程序时,我都会遇到异常
Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'nameOrConnectionString')
我在我的 sql 服务器上创建了数据库“WhmHangFire”。
我仍然得到同样的例外。有人可以解释是什么导致了这个问题吗?
谢谢