title: HTTP Error 500: localhost is currently unable to handle this request
body: <p>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 <code>http://localhost:5000</code>, and the error pops up. The Chrome Developer Tools windows shows this single error:</p>
  
  <pre><code>Failed to load resource: the server responded with a status of 500 (Internal Server Error) http://localhost:5000/
  </code></pre>
  
  <p>Here is my Startup.cs file (exluding using statements for simplicity):</p>
  
  <pre><code>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&lt;Startup&gt;()
                 .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 =&gt;
              {
                  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 =&gt;
              {
                  routes.MapRoute(
                      name: "default",
                      template: "{controller=Home}/{action=Index}");
              });
  
  
              lifetime.ApplicationStopping.Register(() =&gt;
              {
                  Log.Debug("Application Stopping. Do stuff.");
              });
          }
      }
  }
  </code></pre>
  
  <p>With MVC, this causes the HomeController Index method to get called:</p>
  
  <pre><code>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;
          }
      }
  }
  </code></pre>
  
  <p>and here is my Index.cshtml file (which has been placed in Views/Home):</p>
  
  <pre><code>@{
      ViewBag.Title = "Tuner";
  }
  
  @section pageHead {
  }
  
  @section scripts {
      &lt;script src="~/vendor.bundle.js"&gt;&lt;/script&gt; 
      &lt;script src="~/main.bundle.js"&gt;&lt;/script&gt;
  
  }
  
  &lt;cache vary-by="@Context.Request.Path"&gt;
      &lt;app&gt;Loading content...&lt;/app&gt;
  &lt;/cache&gt;
  </code></pre>