2

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>();
                });
    }
WannBo
  • 49
  • 2
  • 7
  • 1
    did you set stdoutLogEnabled = true on web.config file? – MestreDosMagros Oct 25 '20 at 23:27
  • can you provide your startup class? – MestreDosMagros Oct 25 '20 at 23:33
  • Does this answer your question? [ASP.NET Core hosting - 500 internal server error](https://stackoverflow.com/questions/41526919/asp-net-core-hosting-500-internal-server-error) – Jim G. Oct 25 '20 at 23:34
  • @ 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 Oct 25 '20 at 23:55
  • System event log is what you might check next. Run a quick report and it should reveal other possible causes, https://docs.jexusmanager.com/tutorials/ancm-diagnostics.html – Lex Li Oct 26 '20 at 00:07
  • System Event Log shows NOTHING as I said in the text above. Nada. I even cleared out every possible log and restarted to be sure to not miss anything. But there is NO log whatsoever that gives a clue. – WannBo Oct 26 '20 at 00:13
  • Have you tried to run this on visual studio in release mode to check if it run? – MestreDosMagros Oct 26 '20 at 00:21
  • Yes, thanks. Both Release and Debug modes (I have been testing all kinds of alternatives for 8 hours now...) – WannBo Oct 26 '20 at 00:35
  • Well, i cant help very much on this case, but what i would do in this case is start removing things from startup and program class to see if it runs after removing something and then start to looking for solutions for the case, starting by this line: .UseContentRoot(Directory.GetCurrentDirectory()), i already had some problems with this :) – MestreDosMagros Oct 26 '20 at 00:45
  • Very often appsettings.production.json gives 500 error. I highly recomend to recheck this file. For the start open this production file in VS. It will show syntax errors. – Serge Oct 26 '20 at 00:58
  • and for my EF context I use something like this: services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddDbContext(); – Serge Oct 26 '20 at 01:07
  • First of all you have to make sure you have permission to operate .\logs\stdout. You can also use Failed Request Tracing Rules in IIS to track requests and view records. As far as I know, the format of the database connection string may cause a 500 error. What is the format of your database connection string? – Ding Peng Oct 26 '20 at 08:40

3 Answers3

1

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!

WannBo
  • 49
  • 2
  • 7
0

Make sure you give IIS_IUSR permission to your root folder.

Jana
  • 1
0

Browse to the website on the server that is hosting it (ie: using localhost) to get a more thorough error message than what is displayed on a non-local host.

Dave Cousineau
  • 12,154
  • 8
  • 64
  • 80