Created
March 7, 2018 03:42
-
-
Save poojarsn/6bdadefc538b557f8d665ce32bcee391 to your computer and use it in GitHub Desktop.
Sitecore Pipeline HttpBeginRequest - Processor HttpRequestProcessor : Intercept requests before page get processed completely.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Sitecore; | |
using Sitecore.Pipelines.HttpRequest; | |
using System.Web.Security; | |
namespace MyProject.Customm.Pipelines.HttpRequest | |
{ | |
/// <summary> | |
/// The pipeline processor intercept site setting EnabledMaintenance flag before request get processed. | |
/// </summary> | |
public class SiteHandler : HttpRequestProcessor | |
{ | |
private const string _enabeledMaintenancePage = "1"; | |
public override void Process(HttpRequestArgs args) | |
{ | |
if (args != null) | |
{ | |
var siteSettingItem = Context.Database?.GetItem(new Sitecore.Data.ID("{Some Item Id guid}")); | |
if (siteSettingItem != null) | |
{ | |
var enabeledMaintenancePage = siteSettingItem["EnableMaintenancePageFieldName"]; | |
// If login page Item shoudl be checked otherwise it will results into - TOO MANY REDIRECTS. | |
if (enabeledMaintenancePage == _enabeledMaintenancePage) | |
{ | |
//If user session is still available. | |
args.Context.Session?.Abandon(); | |
args.Context.Session?.Clear(); | |
args.Context.Response?.Cookies?.Clear(); | |
FormsAuthentication.SignOut(); | |
args.Context.Response.Redirect("Maintenance Page URL"); | |
//Abort pipeline to prevent: Too many redirects. | |
args.AbortPipeline(); | |
return; | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment