我使用.net core 3.1创建了一个API,就像这样的东西,在我的电脑上可以工作。但当我尝试将其发布到IIS时,它也无法在我的电脑上工作。我必须使用IIS作为我的要求之一。所以错误信息如下:
物理路径为'C:\inetpub\wwwroot\appnamehere\'的应用程序'/LM/W3SVC/2/ROOT'无法加载coreclr。异常信息:CLR工作线程过早退出。该应用程序遇到意外的托管异常,异常代码为'0xe0434352'。所捕获的标准输出和标准错误日志的前30KB字符如下:未处理的异常。System.IO.FileNotFoundException: 找不到文件 'C:\inetpub\wwwroot\appnamehere\appsettings..json'。文件名:'C:\inetpub\wwwroot\appnamehere\appsettings..json' 。 在 C:\Development\solutionNameHere\appnamehere.Services.Configurations\DatabaseConfigProvider.cs 的第25行,调用方法appnamehere.Services.Configurations.DatabaseConfigProvider.FetchConfiguration()读取配置。在 C:\Development\solutionNameHere\appnamehere.Services.Configurations\DatabaseConfigProvider.cs 的第20行,调用方法appnamehere.Services.Configurations.DatabaseConfigProvider.Load()加载配置。 在IList的提供程序中创建Microsoft.Extensions.Configuration.ConfigurationRoot。在C:\Development\solutionNameHere\appnamehere\Services\Configurations\AppConfiguration.cs的第34行,调用方法appnamehere.Services.Configurations.AppConfiguration.GetCurrentSettings()获取当前设置。在C:\Development\solutionNameHere\appnamehere\Services\Configurations\AppConfiguration.cs的第24行,调用属性appnamehere.Services.Configurations.AppConfiguration.Current获取当前设置。在C:\Development\solutionNameHere\appnamehere\Services\Data\Implementation\TitanDbContext.cs的第17行,调用方法appnamehere.Services.Data.Implementation.TitanDbContext.OnConfiguring(DbContextOptionsBuilder optionsBuilder)指定数据库连接字符串。在Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()的第一次调用之后,一个异常被抛出,表明文件C:\inetpub\wwwroot\appnamehere\appsettings..json未找到。
- HTTP 错误 500.30 - ANCM 进程内启动失败。我尝试了很多方法,但似乎没有什么起作用。我检查了appsettings文件以查看是否错过了逗号或其他内容,并更改了IIS中的设置,使应用程序池不管理代码并禁用了32位应用程序选项。
- 未处理异常。System.IO.FileNotFoundException: 找不到文件'C:\ inetpub \ wwwroot \ appnamehere \ appsettings..json'。我在事件查看器中找到了这个问题。
物理路径为'C:\inetpub\wwwroot\appnamehere\'的应用程序'/LM/W3SVC/2/ROOT'无法加载coreclr。异常信息:CLR工作线程过早退出。该应用程序遇到意外的托管异常,异常代码为'0xe0434352'。所捕获的标准输出和标准错误日志的前30KB字符如下:未处理的异常。System.IO.FileNotFoundException: 找不到文件 'C:\inetpub\wwwroot\appnamehere\appsettings..json'。文件名:'C:\inetpub\wwwroot\appnamehere\appsettings..json' 。 在 C:\Development\solutionNameHere\appnamehere.Services.Configurations\DatabaseConfigProvider.cs 的第25行,调用方法appnamehere.Services.Configurations.DatabaseConfigProvider.FetchConfiguration()读取配置。在 C:\Development\solutionNameHere\appnamehere.Services.Configurations\DatabaseConfigProvider.cs 的第20行,调用方法appnamehere.Services.Configurations.DatabaseConfigProvider.Load()加载配置。 在IList的提供程序中创建Microsoft.Extensions.Configuration.ConfigurationRoot。在C:\Development\solutionNameHere\appnamehere\Services\Configurations\AppConfiguration.cs的第34行,调用方法appnamehere.Services.Configurations.AppConfiguration.GetCurrentSettings()获取当前设置。在C:\Development\solutionNameHere\appnamehere\Services\Configurations\AppConfiguration.cs的第24行,调用属性appnamehere.Services.Configurations.AppConfiguration.Current获取当前设置。在C:\Development\solutionNameHere\appnamehere\Services\Data\Implementation\TitanDbContext.cs的第17行,调用方法appnamehere.Services.Data.Implementation.TitanDbContext.OnConfiguring(DbContextOptionsBuilder optionsBuilder)指定数据库连接字符串。在Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()的第一次调用之后,一个异常被抛出,表明文件C:\inetpub\wwwroot\appnamehere\appsettings..json未找到。
于是我去了那个位置,那里有我的所有appsettings文件,包括appsettings.json和appsettings.Development.json。然后我去看出错的地方。
public class Program
{
public static void Main(string[] args)
{
try
{
var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
var host = CreateHostBuilder(args, env).Build();
host.Run();
}
catch (Exception ex)
{
throw;
}
finally
{
NLog.LogManager.Shutdown();
}
}
public static IHostBuilder CreateHostBuilder(string[] args, string env) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.ConfigureAppConfiguration((IConfigurationBuilder builder) =>
{
builder.Sources.Clear();
builder.SetBasePath(Directory.GetCurrentDirectory());
builder.AddDataBaseProvider();
builder.AddJsonFile($"appsettings.{env}.json");
})
.ConfigureLogging((hostingContext, logging) =>
{
logging.ClearProviders();
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
logging.AddConsole();
logging.AddDebug();
logging.AddEventSourceLogger();
logging.AddFile(hostingContext.Configuration.GetSection("Logging"));
});
}
我尝试使用硬编码builder.AddJsonFile($"appsettings.{env}.json");
来明确引用 appsettings.Development.json,但错误仍然存在。
在发布后如何使应用程序看到appsettings.Development.json文件? 在Visual Studio中运行时它完美运行。