mirror of https://github.com/abpframework/abp.git
csharpabpc-sharpframeworkblazoraspnet-coredotnet-coreaspnetcorearchitecturesaasdomain-driven-designangularmulti-tenancy
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.2 KiB
39 lines
1.2 KiB
using System.Net;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Volo.Abp.DependencyInjection;
|
|
using Volo.Abp.Features;
|
|
using Volo.CmsKit.Features;
|
|
using Volo.CmsKit.Public.Pages;
|
|
|
|
namespace Volo.CmsKit.Public.Web;
|
|
|
|
public class PageRoutingMiddleware : IMiddleware, ITransientDependency
|
|
{
|
|
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
|
|
{
|
|
await next(context);
|
|
|
|
if (context.Response.StatusCode == (int)HttpStatusCode.NotFound)
|
|
{
|
|
var featureChecker = context.RequestServices.GetRequiredService<IFeatureChecker>();
|
|
if (!await featureChecker.IsEnabledAsync(CmsKitFeatures.PageEnable))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var pagePublicAppService = context.RequestServices.GetRequiredService<IPagePublicAppService>();
|
|
|
|
var slug = context.Request.Path.ToString().TrimStart('/');
|
|
var exist = await pagePublicAppService.DoesSlugExistAsync(slug);
|
|
|
|
if (exist)
|
|
{
|
|
context.Request.Path = $"/pages/{slug}";
|
|
|
|
await next(context);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|