小编Die*_*gos的帖子

UseStatusCodePagesWithReExecute() 不适用于 .NET Core 3.1

UseStatusCodePagesWithReExecute如果应用程序出现问题,我通常会将用户重定向到错误页面。

如果我的应用程序中发生错误(例如代码 500),我不会被重定向到“/Home/Error”。如果我手动调用它“/Home/Error”就可以了!

这是我的代码,错误在哪里?

        public IActionResult Error(string code)
        {
            return View(new ErrorModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier, ErrorStatusCode = code });
        }



public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseSiteOfflineMiddleware(); 

            app.UseStatusCodePagesWithReExecute("/Home/Error", "?code={0}");

            app.UseStaticFiles();
            app.UseRouting();

            app.UseAuthentication(); 
            app.UseAuthorization();
            app.UseSession(); // Aggiungi Supporto Sessioni

            // Dependency Injection Option per leggere Localizzazione File Resources delle lingue
            var localizationOptions = app.ApplicationServices.GetService<IOptions<RequestLocalizationOptions>>().Value;
            app.UseRequestLocalization(localizationOptions);

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "products",
                    pattern: "{codLanguage}/shop/{id}/{nameProduct}",
                    new { controller = "Catalog", action = "Detail" });

                endpoints.MapControllerRoute(
                    name: "catalog",
                    pattern: …
Run Code Online (Sandbox Code Playgroud)

.net .net-core asp.net-core

3
推荐指数
1
解决办法
5909
查看次数

标签 统计

.net ×1

.net-core ×1

asp.net-core ×1