问题描述
我有一个使用Web Core API的MVC网站.进行较小的更改和部署后,我意外地收到了错误;响应状态代码不表示成功:500(内部服务器错误).因此,我为Web Core API启用了日志文件(请参阅 https://docs.microsoft.com/zh-cn/aspnet/core/host-and-deploy/iis/troubleshoot?view=aspnetcore -2.0#aspnet-core-module-stdout-log ),我收到此错误消息;
I have an MVC website that uses a Web Core API.After making a minor change and a deployment I unexpectedly got an error; Response status code does not indicate success: 500 (Internal Server Error).So I enabled the log file for the Web Core API (see https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/troubleshoot?view=aspnetcore-2.0#aspnet-core-module-stdout-log) and I get this error message;
更新:它跌倒的那条线是;
UPDATE:The line where it is falling over is;
在ConfigureServices中.
in ConfigureServices.
我该如何调试它以找出导致此问题的原因?
How do I debug this to find out what is causing this?
public class Startup {
public Startup(IHostingEnvironment env) {
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appSettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($ "appSettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
.
.
.
.
.
public void ConfigureServices(IServiceCollection services)
{
services.AddCors();
services.AddMvcCore().AddJsonFormatters();
services.Configure<IISOptions>(options => new IISOptions
{
AutomaticAuthentication = true,
ForwardClientCertificate = false,
ForwardWindowsAuthentication = false
});
var connectionStringMSurveyV2 = Configuration.GetConnectionString("MSurveyV2Db");
services.AddScoped<MSurveyV2Db>(_ => new MSurveyV2Db(connectionStringMSurveyV2));
var connectionStringSir = Configuration.GetConnectionString("SirDb");
services.AddScoped<SirDb>(_ => new SirDb(connectionStringSir));
services.AddScoped<IPropertiesRepo, PropertiesRepo>();
services.AddScoped<ISirUoW, SirUoW>();
services.AddScoped<IPropertyUoW, PropertyUoW>();
services.AddScoped<Services.IMailService, Services.MailService>();
}
...
推荐答案
您没有说要使用哪个版本的ASP.NET Core.如果是2.0+,则可以将Program.cs
中的NLog配置为在启动之前加载:
You didn't say which version of ASP.NET Core you are using. If it's 2.0+, you can configure NLog in Program.cs
to load before Startup:
public static class Program
{
public static void Main(string[] args)
{
var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();
try
{
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("hosting.json", optional: true)
.Build();
BuildWebHost(args, config).Run();
}
catch (System.Exception ex)
{
logger.Error(ex, "An error occurred during program startup");
throw;
}
}
private static IWebHost BuildWebHost(string[] args, IConfigurationRoot config)
{
return WebHost.CreateDefaultBuilder(args)
.UseConfiguration(config)
.UseStartup<Startup>()
.UseNLog()
.Build();
}
}
这篇关于如何在Web Core API中调试启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!