mirror of https://github.com/abpframework/abp.git
1 changed files with 11 additions and 15 deletions
@ -1,28 +1,24 @@ |
|||
using System.Threading.Tasks; |
|||
using System.Net; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Http; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.CmsKit.Pages; |
|||
using Volo.CmsKit.Public.Pages; |
|||
|
|||
namespace Volo.CmsKit.Public.Web; |
|||
|
|||
public class DefaultHomePageMiddleware |
|||
public class DefaultHomePageMiddleware : IMiddleware, ITransientDependency |
|||
{ |
|||
private readonly RequestDelegate _next; |
|||
private readonly IPagePublicAppService _pagePublicAppService; |
|||
|
|||
public DefaultHomePageMiddleware(RequestDelegate next, IPagePublicAppService pagePublicAppService) |
|||
{ |
|||
_next = next; |
|||
_pagePublicAppService = pagePublicAppService; |
|||
} |
|||
public async Task InvokeAsync(HttpContext httpContext) |
|||
public async Task InvokeAsync(HttpContext context, RequestDelegate next) |
|||
{ |
|||
var _pagePublicAppService = context.RequestServices.GetRequiredService<IPagePublicAppService>(); |
|||
var page = await _pagePublicAppService.FindDefaultHomePageAsync(); |
|||
if (page is not null && httpContext.Request.Path.Value == "/") |
|||
if (page is not null && context.Request.Path.Value == "/") |
|||
{ |
|||
httpContext.Request.Path = $"{PageConsts.UrlPrefix}{page.Slug}"; |
|||
context.Request.Path = $"{PageConsts.UrlPrefix}{page.Slug}"; |
|||
} |
|||
|
|||
await _next(httpContext); |
|||
|
|||
await next(context); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue