HTTP Error 500: localhost is currently unable to handle this request

56,573

Solution 1

I got the following error hosing an ASP.NET Core 3.1 application on IIS 10.0 after following this guide:

https://docs.microsoft.com/en-us/aspnet/core/tutorials/publish-to-iis?view=aspnetcore-3.1&tabs=visual-studio

This page isn't working
localhost is currently unable to handle this request.
HTTP ERROR 500

enter image description here

If you are on Windows:

Start Event Viewer -> Windows Logs -> Application.

enter image description here

In my case I had the error below and could continue from there (Allow my Application Pool User to access localdb).

Microsoft.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 -Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.

Solution 2

You, like me, might need to install ASP.NET!

On Windows Server 2012 R2 this can be done via the Turn Windows features on or off feature:

  1. Complete the Before You Begin, Installation Type, and Server Selection steps of the wizard.
  2. Under Server Roles, find the Web Server (IIS) node and expand it.
  3. Expand the Web Server node.
  4. Expand the Application Development node.
  5. Check the ASP.NET 3.5 or ASP.NET 4.5 nodes, as appropriate.
  6. Finish the Add Roles and Features Wizard.

Solution 3

In your setup the UseIISIntegration "interferes" with UseUrls, as the UseUrls setting is for the Kestrel process and not the IISExpress/IIS.

If you want to change the IIS Port, have a look at Properties/launchSettings.json - there you can configure the applicationUrl IIS is using.

You could remove the UseIISIntegration for testing purposes and then you can connect to Port 5000, but you never should use Kestrel as Internet facing Server, it should always be run behind a Reverse Proxy like IIS or Nginx, etc.

See the Hosting Docs Page for more information.

Solution 4

I was using IIS (I'm unclear if OP was trying to use IIS), but I did not Install the .NET Core Windows Server Hosting bundle, as described in instructions like this one. After installing that Module, my app served (i.e. no 500 error)

Solution 5

Run asp.net MVC core 1.1 project in vs2017 also get this error.
Solved by upgrade all NuGet Packages version 1.x to latest 2.x and target framework to .NET Core 2.1.

Share:
56,573
Roka545
Author by

Roka545

Updated on June 04, 2021

Comments

  • Roka545
    Roka545 almost 3 years

    I'm running into an HTPP Error 500 and I'm not sure why. When I start my service, I pop open a Chrome browser and navigate to http://localhost:5000, and the error pops up. The Chrome Developer Tools windows shows this single error:

    Failed to load resource: the server responded with a status of 500 (Internal Server Error) http://localhost:5000/
    

    Here is my Startup.cs file (exluding using statements for simplicity):

    namespace Tuner
    {
        public class Startup
        {
            public static void Main(string[] args)
            {
                var exePath = Process.GetCurrentProcess().MainModule.FileName;
                var directoryPath = Path.GetDirectoryName(exePath);
    
                                    var host = new WebHostBuilder()
                   .CaptureStartupErrors(true)
                   .UseKestrel()
                   .UseUrls("http://localhost:5000")
                   .UseContentRoot(Directory.GetCurrentDirectory())
                   .UseIISIntegration()
                   .UseStartup<Startup>()
                   .Build();
                host.Run();
            }
    
    
            public Startup(IHostingEnvironment env)
            {
                //Setup Logger
                Log.Logger = new LoggerConfiguration()
                    .WriteTo.Trace()
                    .MinimumLevel.Debug()
                    .CreateLogger();
                // Set up configuration sources.
                var builder = new ConfigurationBuilder()
                    .SetBasePath(env.ContentRootPath)
                    .AddJsonFile("appsettings.json");
                //.AddEnvironmentVariables();
                Configuration = builder.Build();
            }
    
            public IConfigurationRoot Configuration { get; set; }
    
            // This method gets called by the runtime. Use this method to add services to the container.
            public void ConfigureServices(IServiceCollection services)
            {
                services.AddSwaggerGen();
    
                services.AddMvc().AddJsonOptions(options =>
                {
                    options.SerializerSettings.ContractResolver =
                        new CamelCasePropertyNamesContractResolver();
                });
            }
    
            // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
            public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime lifetime)
            {
    
                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                }
                else
                {
                    app.UseExceptionHandler("/Home/Error");
                }
    
                app.UseStaticFiles();
    
                app.UseMvc(routes =>
                {
                    routes.MapRoute(
                        name: "default",
                        template: "{controller=Home}/{action=Index}");
                });
    
    
                lifetime.ApplicationStopping.Register(() =>
                {
                    Log.Debug("Application Stopping. Do stuff.");
                });
            }
        }
    }
    

    With MVC, this causes the HomeController Index method to get called:

    namespace Tuner.Controllers
    {
        public class HomeController : Controller
        {
            public string appVersion = typeof(HomeController).Assembly.GetName().Version.ToString();
            public string appName = "Empty Web App";
    
            [HttpGet("/")]
            public IActionResult Index()
            {
                var url = Request.Path.Value;
                if (url.EndsWith(".ico") || url.EndsWith(".map"))
                {
                    return new StatusCodeResult(404);
                }
                else
                {
                    // else block is reached
                    return View("~/Views/Home/Index.cshtml");
                }
            }
    
            public IActionResult Error()
            {
                return View("~/Views/Shared/Error.cshtml");
            }
    
            [HttpGetAttribute("app/version")]
            public string Version()
            {
                return appVersion;
    
            }
    
            [HttpGetAttribute("app/name")]
            public string ProjectName()
            {
                return appName;
            }
        }
    }
    

    and here is my Index.cshtml file (which has been placed in Views/Home):

    @{
        ViewBag.Title = "Tuner";
    }
    
    @section pageHead {
    }
    
    @section scripts {
        <script src="~/vendor.bundle.js"></script> 
        <script src="~/main.bundle.js"></script>
    
    }
    
    <cache vary-by="@Context.Request.Path">
        <app>Loading content...</app>
    </cache>