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>
Create a 'php.ini' blank fileini. Insert the following code: memory=64MB. Save the file and upload it into the /wp-admin/ folder using FTP.
The HyperText Transfer Protocol (HTTP) 500 Internal Server Error server error response code indicates that the server encountered an unexpected condition that prevented it from fulfilling the request. This error response is a generic "catch-all" response.
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
If you are on Windows:
Start Event Viewer -> Windows Logs -> Application.
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.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With