You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[AttributeUsage(AttributeTargets.Method|AttributeTargets.Class,AllowMultiple=false)]publicclassMyControllerExceptionFilterAttribute:ExceptionFilterAttribute{protectedreadonlyIHostingEnvironment_hostingEnvironment;protectedreadonlyIModelMetadataProvider_modelMetadataProvider;publicMyControllerExceptionFilterAttribute(IHostingEnvironmenthostingEnvironment,IModelMetadataProvidermodelMetadataProvider){_hostingEnvironment=hostingEnvironment;_modelMetadataProvider=modelMetadataProvider;}publicoverridevoidOnException(ExceptionContextcontext){if(context.ExceptionHandled)return;varresult=newViewResult{ViewName="ApplicationError"};context.ExceptionHandled=true;// mark exception as handledcontext.HttpContext.Response.Clear();context.Result=result;}}
this works fine in asp.net core 1.0, while in asp.net core 1.1 the result is not rendered anymore and the returned http response is like this:
HTTP/1.1 200 OK
Server: Kestrel
X-SourceFiles: =?UTF-8?B?QzpcUHJvamVjdHNcaW50ZXJhaC52aXN1YWxzdHVkaW8uY29tXEludmVudGFyaW9cTWFpblxTb3VyY2VcRnJvbnRvZmZpY2Vcc3JjXEZyb250b2ZmaWNl?=
X-Powered-By: ASP.NET
Date: Wed, 30 Nov 2016 14:49:53 GMT
Content-Length: 0
You can reproduce very easily in this way
create a new ASP.NET Core Web Application (.NET Framework). by default asp.net core 1.0 is installed. then add the controller the ExceptionFilterAttribute above and a very simple ApplicationError view: the view is rendered
update to asp.net core 1.1 then excecute: the view is not rendered and the returned page is blank
comment the row 'context.ExceptionHandled = true;' in ExceptionFilterAttribute: at this point the view is rendered as in step 1.
my conclusion is that 'context.ExceptionHandled = true' is not working as expected
I have a very simple controller with an ExceptionFilterAttribute that throws an exception
this is the ExceptionFilterAttribute
this works fine in asp.net core 1.0, while in asp.net core 1.1 the result is not rendered anymore and the returned http response is like this:
You can reproduce very easily in this way
my conclusion is that 'context.ExceptionHandled = true' is not working as expected
I've made this small project to demostrate the behavior https://www.dropbox.com/s/dl1xa7d2nzy48o8/WebApplication3.zip?dl=0