From 9a9fd29e1e44a21c43ff557348aea65cb90ea26c Mon Sep 17 00:00:00 2001 From: xiang <27800734@qq.com> Date: Wed, 7 May 2025 16:33:57 +0800 Subject: [PATCH] 1 --- Yes.Application/Installs/InstallCommandHandler.cs | 3 +++ Yes.Application/Yes.Application.csproj | 1 + Yes.Blog/Yes.Blog.csproj | 1 + Yes.Domain/Configurations/BlogSettings.cs | 4 ++-- Yes.Domain/Core/Extensions/HttpContextExtensions.cs | 8 ++++++++ 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Yes.Application/Installs/InstallCommandHandler.cs b/Yes.Application/Installs/InstallCommandHandler.cs index f630f8b..eb38057 100644 --- a/Yes.Application/Installs/InstallCommandHandler.cs +++ b/Yes.Application/Installs/InstallCommandHandler.cs @@ -13,6 +13,7 @@ public class InstallCommandHandler( IConnectionStringProvider connectionStringProvider, + IHttpContextAccessor accessor, IMigratorProvider migratorProvider, IWebHostEnvironment env, IConfigurationService configurationService, @@ -25,6 +26,7 @@ private readonly IConfigurationService _configurationService = configurationService; private readonly IWebHostEnvironment _env = env; private readonly IFileService _fileService = fileService; + private readonly IHttpContextAccessor _accessor = accessor; public async Task Handle(InstallCommand request, CancellationToken cancellationToken) { if (!string.IsNullOrEmpty(_settings.ConnectionString) && !string.IsNullOrEmpty(_settings.DatabaseType) && !string.IsNullOrEmpty(_settings.DatabaseName)) @@ -50,6 +52,7 @@ var settings = new BlogSettings(); + settings.Url = _accessor.HttpContext?.GetCurrentDomain() ?? ""; settings.DatabaseName = databaseName; settings.DatabaseType = databaseType.ToString(); diff --git a/Yes.Application/Yes.Application.csproj b/Yes.Application/Yes.Application.csproj index 0103473..840a725 100644 --- a/Yes.Application/Yes.Application.csproj +++ b/Yes.Application/Yes.Application.csproj @@ -12,6 +12,7 @@ + diff --git a/Yes.Blog/Yes.Blog.csproj b/Yes.Blog/Yes.Blog.csproj index ee56d38..747e329 100644 --- a/Yes.Blog/Yes.Blog.csproj +++ b/Yes.Blog/Yes.Blog.csproj @@ -44,6 +44,7 @@ + diff --git a/Yes.Domain/Configurations/BlogSettings.cs b/Yes.Domain/Configurations/BlogSettings.cs index b92f442..e675677 100644 --- a/Yes.Domain/Configurations/BlogSettings.cs +++ b/Yes.Domain/Configurations/BlogSettings.cs @@ -11,9 +11,9 @@ public string Name { get; set; } = "我的博客"; - public string Logo { get; set; } = "https://img.yescent.com/FosQ9ua_nPhlNQwYgJwUXi9MFsB5.jpg"; + public string Logo { get; set; } = ""; - public string Url { get; set; } = "https://yescent.com"; + public string Url { get; set; } = "https://blog.yescent.com"; public int PageSizeOfHomepage { get; set; } = 5; diff --git a/Yes.Domain/Core/Extensions/HttpContextExtensions.cs b/Yes.Domain/Core/Extensions/HttpContextExtensions.cs index 9596905..12cc2e2 100644 --- a/Yes.Domain/Core/Extensions/HttpContextExtensions.cs +++ b/Yes.Domain/Core/Extensions/HttpContextExtensions.cs @@ -17,5 +17,13 @@ namespace Yes.Domain.Core.Extensions } return ipAddress ?? ""; } + + public static string GetCurrentDomain(this HttpContext httpContext) + { + var request = httpContext.Request; + var host = request.Headers["X-Forwarded-Host"].FirstOrDefault() ?? request.Host.Host; + var protocol = request.Headers["X-Forwarded-Proto"].FirstOrDefault() ?? request.Scheme; + return $"{protocol}://{host}"; + } } }