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
{{ message }}
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
I have created a custom Exception filter which looks like this...
public class EntityNotFoundResultHandlerAttribute : ExceptionFilterAttribute
{
public override void OnException(ExceptionContext context)
{
if (!(context.Exception is ArgumentOutOfRangeException)) return;
context.ExceptionHandled = true;
context.Result = new NotFoundResult();
}
}
I changed it to this, hoping for it to either blow up or loop itself, but the end result was the same...
public class EntityNotFoundResultHandlerAttribute : ExceptionFilterAttribute
{
public override void OnException(ExceptionContext context)
{
if (!(context.Exception is ArgumentOutOfRangeException)) return;
context.ExceptionHandled = true;
context.Result = new ViewResult { ViewName = "ImAFish" };
}
}
This is being used within an action like this...
[EnsureServicePortalContext]
[EntityNotFoundResultHandler]
public async Task<IActionResult> Details(Guid id)
{
var model = await employerViewModelBuilder.Build(id);
if (session.CurrentPortalContext.CurrentContextId != null && !model.LinkedServiceOperatorIDs.Contains(session.CurrentPortalContext.CurrentContextId.Value))
return new NotFoundResult();
return View(model);
}
I have stepped through the code to validate that the OnException method of the filter is being run (it runs fine) and to check that code execution is not returning to the Action (it doesn't).
If I remove the exception handled line then the filter executes twice then the expected result (a 404) is returned...
public class EntityNotFoundResultHandlerAttribute : ExceptionFilterAttribute
{
public override void OnException(ExceptionContext context)
{
if (!(context.Exception is ArgumentOutOfRangeException)) return;
//context.ExceptionHandled = true;
context.Result = new NotFoundResult();
}
}
/cc @Eilon - something funky is going on with 1.1.0 and exception filters - we made changes in this area for 1.1.0 so we should have someone investigate this as a potential patch candidate.
From @tiefling on November 16, 2016 12:43
I have created a custom Exception filter which looks like this...
I changed it to this, hoping for it to either blow up or loop itself, but the end result was the same...
This is being used within an action like this...
I have stepped through the code to validate that the OnException method of the filter is being run (it runs fine) and to check that code execution is not returning to the Action (it doesn't).
If I remove the exception handled line then the filter executes twice then the expected result (a 404) is returned...
Copied from original issue: dotnet/aspnetcore#1820
The text was updated successfully, but these errors were encountered: