Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

app.UseExceptionHandler("Home/Error") not going to Home/Error

I created a simple Home/Error page that I can go to directly with no problem. It just returns some static HTML for now. When I change Startup.cs to this:

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        loggerFactory.AddConsole(Configuration.GetSection("Logging"));
        loggerFactory.AddDebug();

        if (env.IsDevelopment())
        {

            app.UseBrowserLink();
            //app.UseDeveloperExceptionPage();
            app.UseExceptionHandler("/Home/Error");

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

        app.UseIISPlatformHandler();
        app.UseSession();
        app.UseStaticFiles();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });
    }

I would expect to get redirected to Home/Error. Instead I am getting a blank screen and if I look at the "Network" tab in Chrome Developer tools, I see a 500 Status returned from my "Home/TestException" action which throws an exception.

If I switch it to app.UseDeveloperExceptionPage(), that page comes up just fine. Any ideas why this is not working?

I am using .Net Core 1.0.0-rc1-update1.

Here are "dependencies" from Project.json:

"dependencies": {
  "AutoMapper": "4.2.1",
  "Dapper": "1.42.0",
  "Microsoft.AspNet.DataProtection": "1.0.0-rc1-final",
  "Microsoft.AspNet.Diagnostics": "1.0.0-rc1-final",
  "Microsoft.AspNet.Http.Abstractions": "1.0.0-rc1-final",
  "Microsoft.AspNet.Identity.EntityFramework": "2.2.1",
  "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
  "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
  "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
  "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
  "Microsoft.AspNet.Session": "1.0.0-rc1-final",
  "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
  "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
  "Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
  "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
  "Microsoft.Extensions.Logging": "1.0.0-rc1-final",
  "Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
  "Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
  "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc1-final",
  "Newtonsoft.Json": "8.0.3",
  "Oracle.ManagedDataAccess": "12.1.24160419",
  "System.Net.Http": "4.0.0"
},
like image 239
Brian Edwards Avatar asked Jul 29 '26 19:07

Brian Edwards


1 Answers

app.UseStatusCodePagesWithReExecute seems to work well:

 if (env.IsDevelopment())
 {
     app.UseDeveloperExceptionPage();
     app.UseDatabaseErrorPage();
     app.UseBrowserLink();
 }
 else
 {
     app.UseStatusCodePagesWithReExecute("/Home/Error");
 }
like image 172
Miriam Zusin Avatar answered Aug 05 '26 10:08

Miriam Zusin