我完全被 IIS 10 上的一个简单的 .net-core 3.1 应用程序困住了,它顽固地给出“500 内部错误”,但拒绝提供有关该问题的任何日志或任何其他提示。
该应用程序在开发环境中以及使用“dotnet myapp.dll”启动时运行良好。
<aspNetCore processPath=".\MyApp.exe" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
我可以使用“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 程序类,我在其中测试了机器人 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 权限,因此自动(!)创建的应用程序目录永远不会继承必要的权限。我一开始就仔细设置了权限。
谢谢!
浏览到托管它的服务器上的网站(即:使用本地主机)以获得比非本地主机上显示的更全面的错误消息。
确保您授予 IIS_IUSRS 根文件夹权限。