ASP.NET Core MVC - Developer Exception Page

ASP.NET Core MVC - Developer Exception Page
GO
  • Rejestracja:około 9 lat
  • Ostatnio:8 miesięcy
  • Postów:147
0

Cześć,

Zacząłem uczyć się tego frameworka i próbuję wyrzucić na chroma błąd i podgląd stosu:

Kopiuj

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace KudvenkatCourse
{
    public class Startup
    {
        private IConfiguration _config;
        public Startup(IConfiguration config)
        {
            _config = config;
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
        }

        // 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();

                app.UseWelcomePage("/IIS");
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            FileServerOptions dfo = new FileServerOptions();
            dfo.DefaultFilesOptions.DefaultFileNames.Clear();
            dfo.DefaultFilesOptions.DefaultFileNames.Add("foo.html");
            app.UseFileServer(dfo);
            //app.UseFileServer();
            //app.UseStaticFiles();

            app.UseRouting();
            

            app.Use(async (context, next) =>
            {
                await context.Response.WriteAsync("Hello from .Use!\n");                
                await next();

            });            

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapGet("/", async context =>
                {                    
                    await context.Response.WriteAsync("Hello from .UseEndpoints!\n");
                    await context.Response
                    .WriteAsync(System.Diagnostics.Process.GetCurrentProcess().ProcessName);
                    await context.Response.WriteAsync("\n" + _config["MyKey"]);
                });
            });

            app.Use(async (context, next) =>
            {
                await context.Response.WriteAsync("Hello from .Use 2nd!\n");
                await next();
            });


            app.Run(async (context) =>
            {
                throw new Exception("Holy makarony!");
                await context.Response.WriteAsync("Hello from .Run\n"); 
            });
        }
    }
}



Aplikacja jest do celów testowych i nauki.

app.UseWelcomePage("/IIS"); działa, czyli tryb developerski jest załączany.
A mimo to jak wejdę pod '/abc' to wyświetla mi się napis:
"Hello from .Use!
Hello from .Use 2nd!"
i żadnej obsługi błędów ani nic. Tylko te słowa, ale w Debugu po zatrzymaniu aplikacji pisze:
*Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware: Warning: The response has already started, the error page middleware will not be executed.
*

Swoją drogą czy to nie ".UseEndpoints()" miał być middlewarem terminującym? Zamiast "
.Run()" ? A mimo to to on nawet nie jest wywoływany.


"I just met you, (Thread)
And this is crazy,
But here's my number (delegate),
So if something happens (event),
Call me, maybe (callback)?"
edytowany 1x, ostatnio: gornada
GO
  • Rejestracja:około 9 lat
  • Ostatnio:8 miesięcy
  • Postów:147
0

Dobra, stworzyłem nowy projekt i działa. Musiał coś namieszać w tym, że nie działa. Zamykam


"I just met you, (Thread)
And this is crazy,
But here's my number (delegate),
So if something happens (event),
Call me, maybe (callback)?"

Zarejestruj się i dołącz do największej społeczności programistów w Polsce.

Otrzymaj wsparcie, dziel się wiedzą i rozwijaj swoje umiejętności z najlepszymi.