+
Skip to content

fix bug portal #533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Mix.Cms.Lib/Constants/MixAppSettingKeywords.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public class MixAppSettingKeywords
{
public const string IsInit = "IsInit";
public const string ResponseCache = "ResponseCache";
public const string SiteName = "SiteName";
public const string ConnectionString = "ConnectionString";
public const string SortBy = "SortBy";
Expand Down
16 changes: 16 additions & 0 deletions src/Mix.Cms.Lib/Helpers/MixCmsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,22 @@ public async static Task<RepositoryResponse<PaginationModel<TView>>> GetPostlist

public static string TranslateUrl(string url, string srcCulture, string destCulture)
{
using var context = new MixCmsContext();
string seoUrl = url.TrimStart('/').Replace($"{srcCulture}/", string.Empty);
if (context.MixUrlAlias.Any(m => m.Alias == seoUrl))
{
return context.MixUrlAlias.FirstOrDefault(
m => m.Alias == seoUrl && m.Specificulture == destCulture)?.Alias;
}

var page = context.MixPage.FirstOrDefault(m => m.SeoName == seoUrl && m.Specificulture == srcCulture);
if (page != null)
{
var destPage = context.MixPage.FirstOrDefault(
m => m.Id == page.Id && m.Specificulture == destCulture);
return $"/{destCulture}/{destPage.SeoName}";
}

return url.Contains($"/{srcCulture}")
? url.Replace(srcCulture, destCulture)
: $"/{destCulture}{url}";
Expand Down
1 change: 1 addition & 0 deletions src/Mix.Cms.Web/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ protected override void ValidateRequest()

#region Routes


[HttpGet]
public async Task<IActionResult> Index(string seoName, string keyword)
{
Expand Down
6 changes: 6 additions & 0 deletions src/Mix.Cms.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Mix.Heart.Helpers;
using System;
using System.IO;
using Microsoft.Extensions.Logging;

namespace Mix.Cms.Web
{
Expand All @@ -33,6 +34,11 @@ public static IHostBuilder CreateHostBuilder(string[] args)
.AddJsonFile(MixConstants.CONST_FILE_APPSETTING, optional: true, reloadOnChange: true)
.Build();
return Host.CreateDefaultBuilder(args)
.ConfigureLogging(logging =>
{
logging.ClearProviders();
logging.AddConsole();
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
Expand Down
45 changes: 26 additions & 19 deletions src/Mix.Cms.Web/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.ResponseCompression;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.EntityFrameworkCore;
Expand Down Expand Up @@ -47,7 +48,8 @@ public void ConfigureServices(IServiceCollection services)
string[] allowedHosts = MixService.GetAppSetting<JArray>(MixAppSettingKeywords.AllowedHosts)
.Select(m => m.Value<string>("text")).ToArray();

services.AddWebEncoders(options => {
services.AddWebEncoders(options =>
{
options.TextEncoderSettings = new System.Text.Encodings.Web.TextEncoderSettings(UnicodeRanges.All);
});

Expand All @@ -62,8 +64,8 @@ public void ConfigureServices(IServiceCollection services)
});
});

services.AddResponseCompression();
services.AddResponseCaching();


services.AddControllersWithViews()
.AddRazorRuntimeCompilation()
.AddNewtonsoftJson(options =>
Expand Down Expand Up @@ -111,6 +113,7 @@ public void ConfigureServices(IServiceCollection services)
VerifyInitData(services);
/* End Additional Config for Mixcore Cms */

services.AddResponseCaching();
#endregion Additionals Config for Mixcore Cms
}

Expand All @@ -137,26 +140,30 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
}

app.UseResponseCompression();


app.UseCors(MixcoreAllowSpecificOrigins);

app.UseResponseCaching();
app.Use(async (context, next) =>
int responseCache = MixService.GetAppSetting<int>(MixAppSettingKeywords.ResponseCache);
if (responseCache > 0)
{
context.Response.GetTypedHeaders().CacheControl =
new Microsoft.Net.Http.Headers.CacheControlHeaderValue()
{
Public = true,
MaxAge = TimeSpan.FromSeconds(100),
NoStore = false,

};
context.Response.Headers[Microsoft.Net.Http.Headers.HeaderNames.Vary] =
new string[] { "accept-encoding" };

await next();
});
app.UseResponseCaching();
app.Use(async (context, next) =>
{
context.Response.GetTypedHeaders().CacheControl =
new Microsoft.Net.Http.Headers.CacheControlHeaderValue()
{
Public = true,
NoCache = false,
SharedMaxAge = TimeSpan.FromSeconds(responseCache),
MaxAge = TimeSpan.FromSeconds(responseCache),

};
context.Response.Headers[Microsoft.Net.Http.Headers.HeaderNames.Vary] =
new string[] { "Accept-Encoding" };
await next();
});
}

var provider = new FileExtensionContentTypeProvider();
// Add new mappings
Expand Down
Binary file not shown.
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载