.net core 3.1 应用程序在 iis 10 上给出 500 内部错误并且在任何地方都没有日志

问题描述 投票:0回答:3

我完全被 IIS 10 上的一个简单的 .net-core 3.1 应用程序困住了,它顽固地给出“500 内部错误”,但拒绝提供有关该问题的任何日志或任何其他提示。

该应用程序在开发环境中以及使用“dotnet myapp.dll”启动时运行良好。

  • 我只使用 http 端口 80 来让它运行,并删除了“app.UseHttpsRedirection();”来自 Startup.cs
  • 我已在 Windows 2016 服务器上安装了 ASP.NET Core 3.1 Runtime (v3.1.3) - Windows Hosting Bundle
  • 应用程序池是“无托管代码”和“集成管道”
  • 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 程序类,我在其中测试了机器人 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>();
                });
    }
c# asp.net-mvc asp.net-core-3.1 iis-10
3个回答
1
投票

感谢各位大师的帮助和建议!

一如既往,解决方案比预期更简单。

我在发布时使用“删除所有文件”设置以确保进行全新安装。我没有意识到这次发布删除了整个应用程序目录,然后又重新创建了它。由于某种未知的原因,应用程序的父目录丢失了 IIS_IUSRS 权限,因此自动(!)创建的应用程序目录永远不会继承必要的权限。我一开始就仔细设置了权限。

谢谢!


0
投票

浏览到托管它的服务器上的网站(即:使用本地主机)以获得比非本地主机上显示的更全面的错误消息。


0
投票

确保您授予 IIS_IUSRS 根文件夹权限。

© www.soinside.com 2019 - 2024. All rights reserved.