0
votes

I am totally stuck with a simple .net-core 3.1 application on IIS 10 that stubbornly gives "500 Internal error", but refuses to give any logs or any other hint on the problem.

The app works beautifully in dev env and when started with "dotnet myapp.dll".

  • I use only http port 80 just to get it running and have removed "app.UseHttpsRedirection();" from Startup.cs
  • I have installed the ASP.NET Core 3.1 Runtime (v3.1.3) - Windows Hosting Bundle on the Windows 2016 server
  • The application pool is "No managed code" and "integrated pipeline"
  • The site in IIS responds on simple html-pages
  • The app has been published "to folder" as an Application in IIS, both as "Integrated Framework" and as "Self contained"
  • Permissions for all directories are correct in every aspect as I can see.
  • The log directories (I put them everywhere, just in case) are created and present with "Everyone" having write access, and web.config is:
    <aspNetCore processPath=".\MyApp.exe" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
  • I have tested both .UseKestrel() and not in Program.cs

The fact that I can start it and run it with "dotnet myapp.dll" tells me that nothing seems wrong with the application itself.

Is there any way I can get hold of some logs, or a better "500 Internal error page"? There is NOTHING in Windows Event logs, or in W3C logs, and nothing in any .\logs directory. Just the damned "500 Internal error" that give no clue on the real problem.

I would be eternally grateful for some wise suggestions.

// Martin

Addendum, Startup class with a number of comments that has gone on and off during testing:

   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?}");
            });
        }
    }

And FWIW the Program class, where I have tested bot useKestrel and not with the same behavior:

   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>();
                });
    }
1
did you set stdoutLogEnabled = true on web.config file?MestreDosMagros
can you provide your startup class?MestreDosMagros
Does this answer your question? ASP.NET Core hosting - 500 internal server errorJim G.
@ MestreDosMagros Thanks for quick reply. Yes, I have set stdoutLogEnabled = true. And the DB connection works fine when I run it as dotnet myapp.dll. But the start page is passive html and does not use DB, and I fail already there.WannBo
System event log is what you might check next. Run a quick report and it should reveal other possible causes, docs.jexusmanager.com/tutorials/ancm-diagnostics.htmlLex Li

1 Answers

0
votes

Thanks Gurus for kind help and suggestions!

As always, the solution was simpler than expected.

I use "Delete all files" setup when publishing to make sure there is a clean installation. I did not realise that this publishing removed the entire application directory and then recreated it again. And for some reason unknown, the application's parent directory had lost the IIS_IUSRS permission, and thus the automatically (!) created application directory never inherited the necessary permissions. Permissions that I had carefully setup in the first place.

Thanks!