Automatically refresh the page if we encounter a ModelBindingException

This commit is contained in:
Shannon
2019-07-03 19:15:54 +10:00
parent 31716e574c
commit 37bf6fe938
3 changed files with 26 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
using System.Web.Mvc;
namespace Umbraco.Web.Mvc
{
/// <summary>
/// An exception filter checking if we get a <see cref="ModelBindingException"/> in which case it returns the html to auto refresh the page
/// </summary>
internal class ModelBindingExceptionFilter : FilterAttribute, IExceptionFilter
{
public void OnException(ExceptionContext filterContext)
{
if (!filterContext.ExceptionHandled && filterContext.Exception is ModelBindingException)
{
filterContext.Result = new ContentResult
{
Content = "<html><head><meta http-equiv=\"refresh\" content=\"3\" /></head><body><p>Loading page...</p></body></html>",
ContentType = "text/html"
};
filterContext.ExceptionHandled = true;
}
}
}
}

View File

@@ -10,10 +10,12 @@ using Umbraco.Web.Routing;
namespace Umbraco.Web.Mvc
{
/// <summary>
/// Represents the default front-end rendering controller.
/// </summary>
[PreRenderViewActionFilter]
[ModelBindingExceptionFilter]
public class RenderMvcController : UmbracoController, IRenderMvcController
{
private PublishedRequest _publishedRequest;

View File

@@ -218,6 +218,7 @@
<Compile Include="Models\Mapping\MapperContextExtensions.cs" />
<Compile Include="Models\PublishedContent\HybridVariationContextAccessor.cs" />
<Compile Include="Models\TemplateQuery\QueryConditionExtensions.cs" />
<Compile Include="Mvc\ModelBindingExceptionFilter.cs" />
<Compile Include="Mvc\SurfaceControllerTypeCollectionBuilder.cs" />
<Compile Include="Profiling\WebProfilingController.cs" />
<Compile Include="PublishedCache\NuCache\Snap\GenObj.cs" />