如何解决IIS 10上的.net Core 3.1应用程序会产生500个内部错误,并且任何地方都没有日志
我完全受制于IIS 10上的一个简单的.net-core 3.1应用程序,该应用程序顽固地给出“ 500 Internal error”,但拒绝提供有关该问题的任何日志或任何其他提示。
该应用程序在dev env中以及从“ dotnet myapp.dll”启动时都能正常运行。
- 我仅使用http端口80来使其运行,并删除了“ app.UseHttpsRedirection();”来自Startup.cs
- 我已经在Windows 2016服务器上安装了ASP.NET Core 3.1运行时(v3.1.3)-Windows主机捆绑包
- 应用程序池是“无托管代码”和“集成管道”
- IIS中的站点在简单的html页面上响应
- 该应用程序已作为IIS中的应用程序“集成文件夹”和“自包含”发布为“到文件夹”。
- 如我所见,所有目录的权限在各个方面都是正确的。
- 创建日志目录(以防万一,我把它们放在任何地方)并以具有写入权限的“每个人”的形式提供,并且web.config为:
<aspNetCore processPath=".\MyApp.exe" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
- 我已经测试了.UseKestrel(),但未在Program.cs中测试
我可以使用“ dotnet myapp.dll”启动并运行它的事实告诉我,应用程序本身似乎没有问题。
有什么办法可以保存一些日志,或者更好的“ 500内部错误页面”? Windows事件日志或W3C日志中没有任何内容,任何。\ logs目录中都没有任何内容。只是该死的“ 500内部错误”无法为真正的问题提供任何线索。
我将永远感谢一些明智的建议。
//马丁
附录,启动类,其中包含在测试过程中打开和关闭的许多注释:
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.AddControllersWithViews();
services.AddTransient<AppDb>(_ => new AppDb(Configuration["ConnectionStrings:validAndWorkingString"]));
services.AddDistributedMemoryCache();
services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromSeconds(10);
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app,IWebHostEnvironment env)
{
//if (env.IsDevelopment())
//{
app.UseDeveloperExceptionPage();
//}
//else
//{
// app.UseExceptionHandler("/Home/Error");
// // The default HSTS value is 30 days. You may want to change this for production scenarios,see https://aka.ms/aspnetcore-hsts.
// app.UseHsts();
//}
app.UseSession();
// app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
FWIW是Program类,我在其中测试了bot useKestrel,并且行为不相同:
public class Program
{
public static void Main(string[] args)
{
bool useKestrel = true;
if (useKestrel)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
else
{
CreateHostBuilder(args).Build().Run();
}
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
解决方法
感谢古鲁斯的帮助和建议!
与往常一样,解决方案比预期的简单。
发布时,我使用“删除所有文件”设置来确保进行全新安装。我没有意识到此发布会删除整个应用程序目录,然后重新创建它。由于某种未知的原因,该应用程序的父目录失去了IIS_IUSRS权限,因此,自动(!)创建的应用程序目录从未继承必要的权限。首先我已经仔细设置了权限。
谢谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。