【发布时间】:2020-06-03 04:50:21
【问题描述】:
我们在 .Net Core 3.1 中有一个 API 项目。 它在团队中的所有计算机上都可以工作,但是当尝试在新成员计算机上调试它时失败了。 它指出存在服务器错误(500)并且不会启动程序。 它作为本地服务工作,无需 IIS。
我们已尝试格式化计算机并重新开始,但没有用。 我看到了与项目配置和启动设置相关的帖子,但由于它正在其他机器上工作,我认为这不是问题。 我们还尝试在 iis 模板文件和 dll 中添加 aspnetcore 模块所需的行,如在其他推荐它的地方看到的那样,得到了同样的问题。
任何建议将不胜感激!
您的 HttpFailure_08-24-17.tml 文件中的错误文本
注意:您确实应该复制/粘贴为文本,而不是附加屏幕截图:
The description for Event ID 1034 from source IIS Express AspNetCore Module V2 cannot found.
Either the component that raises this event is not installed on your local computer or the installation is corrupted.
You can install or repair the component on the local computer.
...
The following information was included with the event:
Could not load configuration. Exception message: Unable to get required configuration section 'system.webServer/aspNetCore'. Possible reason is web.config authoring error.
The request is not supported.
编辑: 程序.cs:
public class Program
{
public static void Main(string[] args)
{
try
{
Console.Error.WriteLine("Starting application (from error log without errors)");
var config = new ConfigurationBuilder().AddEnvironmentVariables("ASPNETCORE_").Build();
Console.WriteLine("Config set");
var hostBuilder = new WebHostBuilder()
.UseKestrel(opt => opt.AddServerHeader = false)
.UseConfiguration(config)
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>();
Console.WriteLine("hostBuilder set");
// ConfigureServices is only used to delay execution until UseIISIntegration()
// has actually set the "urls" setting.
Console.WriteLine("urls for hostBuilder " + hostBuilder.GetSetting("urls"));
hostBuilder.ConfigureServices(services =>
{
var urls = hostBuilder.GetSetting("urls");
urls = string.IsNullOrWhiteSpace(urls) ? "127.0.0.1" : urls.Replace("localhost", "127.0.0.1");
hostBuilder.UseSetting("urls", urls);
});
Console.WriteLine("hostBuilder.ConfigureServices set");
var host = hostBuilder.Build();
Console.WriteLine("host set");
host.Run();
}
catch (Exception ex)
{
Console.Error.WriteLine(ex.Message);
}
}
}
【问题讨论】:
-
请在 MSVS 中启动您的应用程序,重现 HTTP 500 错误,并仔细查看 MSVS“输出”窗口中的任何错误消息和/或堆栈回溯。请更新您的帖子。
-
@FoggyDay 我只得到 404,这是意料之中的。在帖子中添加了我在运行 IIS Express 时得到的内容(VS 错误和事件日志)
-
通常,运行项目应用程序的“MSVS > Debug”将启动 IIS Express,将打开一个浏览器窗口...并显示所有运行时消息(包括错误) 在 MSVS 输出窗口中。听起来你在做“一些不同的事情”。
-
你看过这篇文章吗?我不知道这是这样工作的,也许它适合你的情况:blog.maartenballiauw.be/post/2019/02/26/…
标签: c# windows-10 iis-express asp.net-core-3.1 .net-core-3.1