Quantcast
Channel: Using Optimizely Platforms
Viewing all articles
Browse latest Browse all 8020

BVN.404Handler - CustomRequestHandler & DXP - truncated response

$
0
0

Hi All,

We developed a custom handler to extend BVN package to server a custom 404 page based on the request URL.

This functionality has been running on our on-prem hosting successfully for some time now. However, one deployed to DXP, the response's content is being truncated so the ever request returns different amounts of HTML.

Handler code:

using BVNetwork.NotFound.Core;
using BVNetwork.NotFound.Core.Configuration;
using BVNetwork.NotFound.Core.CustomRedirects;
using BVNetwork.NotFound.Core.Logging;
using System;
using System.Web;
namespace Goodwood.Web.BVN
{
    public class CustomRequestHandler : RequestHandler
    {
        public CustomRequestHandler(
            IRedirectHandler redirectHandler,
            IRequestLogger requestLogger,
            IConfiguration configuration) : base(redirectHandler, requestLogger, configuration)
        {
        }
        public override void Handle(HttpContextBase context)
        {
            if (context.Response.StatusCode == 404 && !(context.Request.Url?.AbsolutePath.Contains("404") ?? false))
            {
                var isMemberArea = context.Request.Url?.AbsolutePath.StartsWith("/member", StringComparison.InvariantCultureIgnoreCase) ?? false;
                context.Server.TransferRequest($"{(isMemberArea ? "/member" : string.Empty)}/404/");
            }
        }
    }
}

Initialization module:

 [InitializableModule]
    [ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
    public class Custom404HandlerInitialization : IConfigurableModule
    {
        public void Initialize(InitializationEngine context)
        {
        }
        public void Uninitialize(InitializationEngine context)
        {
        }
        public void ConfigureContainer(ServiceConfigurationContext context)
        {
            context.Services.AddTransient<RequestHandler, CustomRequestHandler>();
        }
    }

Is it something you guys have experienced before? 

Thanks, Maciej


Viewing all articles
Browse latest Browse all 8020

Trending Articles