Webiant Logo Webiant Logo
  1. No results found.

    Try your search with a different keyword or use * as a wildcard.

KeepAliveMiddleware.cs

using Microsoft.AspNetCore.Http;
using Nop.Core;
using Nop.Data;

namespace Nop.Services.Common;

/// 
/// Represents middleware that checks whether request is for keep alive
/// 
public partial class KeepAliveMiddleware
{
    #region Fields

    protected readonly RequestDelegate _next;

    #endregion

    #region Ctor

    public KeepAliveMiddleware(RequestDelegate next)
    {
        _next = next;
    }

    #endregion

    #region Methods

    /// 
    /// Invoke middleware actions
    /// 
    /// HTTP context
    /// Web helper
    /// A task that represents the asynchronous operation
    public async Task InvokeAsync(HttpContext context, IWebHelper webHelper)
    {
        //whether database is installed
        if (DataSettingsManager.IsDatabaseInstalled())
        {
            //keep alive page requested (we ignore it to prevent creating a guest customer records)
            var keepAliveUrl = $"{webHelper.GetStoreLocation()}{NopCommonDefaults.KeepAlivePath}";
            if (webHelper.GetThisPageUrl(false).StartsWith(keepAliveUrl, StringComparison.InvariantCultureIgnoreCase))
                return;
        }

        //or call the next middleware in the request pipeline
        await _next(context);
    }

    #endregion
}