mirror of https://github.com/abpframework/abp.git
7 changed files with 66 additions and 23 deletions
@ -0,0 +1,18 @@ |
|||
using Microsoft.AspNetCore.Builder; |
|||
using Volo.Abp.GlobalFeatures; |
|||
using Volo.CmsKit.GlobalFeatures; |
|||
|
|||
namespace Volo.CmsKit.Public.Web; |
|||
|
|||
public static class CmsKitPagesMiddlewareExtensions |
|||
{ |
|||
public static IApplicationBuilder UseHomePageDefaultMiddleware(this IApplicationBuilder builder) |
|||
{ |
|||
return builder.UseMiddleware<DefaultHomePageMiddleware>(); |
|||
} |
|||
|
|||
public static IApplicationBuilder UseCmsKitPagesMiddleware(this IApplicationBuilder builder) |
|||
{ |
|||
return builder.UseMiddleware<PageRoutingMiddleware>(); |
|||
} |
|||
} |
|||
@ -1,11 +0,0 @@ |
|||
using Microsoft.AspNetCore.Builder; |
|||
|
|||
namespace Volo.CmsKit.Public.Web; |
|||
|
|||
public static class HomePageDefaultMiddlewareExtensions |
|||
{ |
|||
public static IApplicationBuilder UseHomePageDefaultMiddleware(this IApplicationBuilder builder) |
|||
{ |
|||
return builder.UseMiddleware<DefaultHomePageMiddleware>(); |
|||
} |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
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 page = await pagePublicAppService.FindBySlugAsync( |
|||
context.Request.Path.ToString().TrimStart('/')); |
|||
|
|||
if (page is not null) |
|||
{ |
|||
context.Request.Path = $"/pages/{page.Slug}"; |
|||
|
|||
await next(context); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue