Sometimes we have written a good program that compiles nicely. We build the project, run the server, and navigate to our app. At some point while navigating through our pages, we get an error and a page isn't returned. This generally results in a 500 server error message in the browser. (We'll cover server messages later.) Unfortunately, this vague message isn't helpful for debugging our code.
In Startup.cs
, we can add a service that will provide a more detailed error message when a Razor page fails to load due to a server error. Within the Configure()
method - the same method that declares app.UseMvc()
- add a new line of code:
...
public void Configure(IApplicationBuilder app)
{
app.UseDeveloperExceptionPage(); //This is the new line of code
...
This will produce a friendly error report when Razor fails to load.
To debug views, add the following code:
...
public void Configure(IApplicationBuilder app)
{
app.UseDeveloperExceptionPage(); //This is the new line of code
...
Lesson 17 of 38
Last updated more than 3 months ago.