diff --git a/.version b/.version index 0de1add..d34ae26 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -1.5.17.26 \ No newline at end of file +1.5.18.27 \ No newline at end of file diff --git a/Netina.Api/Controllers/HealthController.cs b/Netina.Api/Controllers/HealthController.cs index 60407c0..232e7d2 100644 --- a/Netina.Api/Controllers/HealthController.cs +++ b/Netina.Api/Controllers/HealthController.cs @@ -15,7 +15,7 @@ public class HealthController : ICarterModule public async Task GetHealth([FromServices]ISiteMapService siteMapService) { - //await siteMapService.CreateSiteMapAsync(); + await siteMapService.CreateSiteMapAsync(); var version = typeof(Program)?.Assembly.GetName()?.Version?.ToString(); var check = new HealthCheck { diff --git a/Netina.Api/WebFramework/Configurations/ServiceExtensions.cs b/Netina.Api/WebFramework/Configurations/ServiceExtensions.cs index 977c174..eb04e9d 100644 --- a/Netina.Api/WebFramework/Configurations/ServiceExtensions.cs +++ b/Netina.Api/WebFramework/Configurations/ServiceExtensions.cs @@ -72,7 +72,7 @@ public static class ServiceExtensions serviceCollection.AddDbContextFactory(options => { options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking); - options.UseNpgsql(Configuration.GetConnectionString("Postgres"), b => b.MigrationsAssembly("Netina.Repository")) + options.UseNpgsql(Configuration.GetConnectionString("PostgresServer"), b => b.MigrationsAssembly("Netina.Repository")) .UseProjectAssembly(typeof(ApplicationUser).Assembly); //options.EnableServiceProviderCaching(true); diff --git a/Netina.Core/BaseServices/SiteMapService.cs b/Netina.Core/BaseServices/SiteMapService.cs index 8989164..894ff89 100644 --- a/Netina.Core/BaseServices/SiteMapService.cs +++ b/Netina.Core/BaseServices/SiteMapService.cs @@ -1,7 +1,11 @@ using System.IO.Compression; +using System.Net; +using System.Web; using System.Xml; using Netina.Core.Models; +using Netina.Domain.Entities.Brands; using Netina.Domain.Entities.ProductCategories; +using Netina.Domain.Entities.Products; namespace Netina.Core.BaseServices; @@ -125,7 +129,10 @@ public class SiteMapService( foreach (var page in pages) { - var productUrl = $"{_siteSetting.WebSiteUrl}/{page.Slug}"; + string slugHtml = page.Slug; + if (slugHtml.Contains(' ')) + slugHtml = WebUtility.UrlEncode(slugHtml.Replace(' ', '-')); + var productUrl = $"{_siteSetting.WebSiteUrl}/{slugHtml}"; XmlElement urlElement = doc.CreateElement("url", doc.DocumentElement?.NamespaceURI); root.AppendChild(urlElement); @@ -193,7 +200,10 @@ public class SiteMapService( foreach (var brand in brands) { - var productUrl = $"{_siteSetting.WebSiteUrl}/brands/{brand.Id}/{brand.Slug}"; + string slugHtml = brand.Slug; + if (slugHtml.Contains(' ')) + slugHtml = WebUtility.UrlEncode(slugHtml.Replace(' ', '-')); + var productUrl = $"{_siteSetting.WebSiteUrl}/brands/{brand.Id}/{slugHtml}"; XmlElement urlElement = doc.CreateElement("url", doc.DocumentElement?.NamespaceURI); root.AppendChild(urlElement); @@ -262,7 +272,10 @@ public class SiteMapService( foreach (var productCategory in categories) { - var productUrl = $"{_siteSetting.WebSiteUrl}/categories/{productCategory.Id}/{productCategory.Slug}"; + string slugHtml = productCategory.Slug; + if (slugHtml.Contains(' ')) + slugHtml = WebUtility.UrlEncode(slugHtml.Replace(' ', '-')); + var productUrl = $"{_siteSetting.WebSiteUrl}/categories/{productCategory.Id}/{slugHtml}"; XmlElement urlElement = doc.CreateElement("url", doc.DocumentElement?.NamespaceURI); root.AppendChild(urlElement); @@ -335,8 +348,10 @@ public class SiteMapService( foreach (var product in group) { - - var productUrl = $"{_siteSetting.WebSiteUrl}/products/{product.Id}/{product.Slug}"; + string slugHtml = product.Slug; + if (slugHtml.Contains(' ')) + slugHtml = WebUtility.UrlEncode(slugHtml.Replace(' ', '-')); + var productUrl = $"{_siteSetting.WebSiteUrl}/products/{product.Id}/{slugHtml}"; XmlElement urlElement = doc.CreateElement("url", doc.DocumentElement?.NamespaceURI); root.AppendChild(urlElement); @@ -436,7 +451,11 @@ public class SiteMapService( root.AppendChild(urlElement); XmlElement loc = doc.CreateElement("loc", doc.DocumentElement?.NamespaceURI); - loc.InnerText = Path.Combine($"{_siteSetting.WebSiteUrl}/blogs/{blog.Id}/{blog.Slug}"); + + string slugHtml = blog.Slug; + if (slugHtml.Contains(' ')) + slugHtml = WebUtility.UrlEncode(slugHtml.Replace(' ', '-')); + loc.InnerText = Path.Combine($"{_siteSetting.WebSiteUrl}/blogs/{blog.Id}/{slugHtml}"); urlElement.AppendChild(loc); XmlElement lastmod = doc.CreateElement("lastmod", doc.DocumentElement?.NamespaceURI);