I have the following which partially works in the .cshtml.cs but not the .cshtml file:
Do I need to change my GlobalExceptionFilter or do I need to add something else to catch the .cshtml errors?
For both of the errors they do redirect to the /Error page.
public class GlobalExceptionFilter : IExceptionFilter
{
public void OnException(ExceptionContext context)
{
LogError(context.Exception);
}
}
In Startup.cs:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvcOptions(options =>
{
options.Filters.Add<GlobalExceptionFilter>();
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
}
}
In Index.cshtml.cs:
public void OnGet()
{
throw new Exception("Test"); //This hits GlobalExceptionFilter
}
In Index.cshtml:
@{
throw new Exception("Test"); //This does NOT hit GlobalExceptionFilter
}
Thanks in advance