From a8284c0bf1dbfaacb74fab682cabf6917e52921c Mon Sep 17 00:00:00 2001 From: Salih Date: Thu, 16 Feb 2023 19:17:41 +0300 Subject: [PATCH 1/2] Encode URL before saving it into database --- .../src/Volo.Blogging.Web/Pages/Blogs/Posts/Edit.cshtml.cs | 3 ++- .../src/Volo.Blogging.Web/Pages/Blogs/Posts/New.cshtml.cs | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Edit.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Edit.cshtml.cs index 468f2ab191..55bb220d54 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Edit.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Edit.cshtml.cs @@ -50,6 +50,7 @@ namespace Volo.Blogging.Pages.Blog.Posts var postDto = await _postAppService.GetAsync(new Guid(PostId)); Post = ObjectMapper.Map(postDto); Post.Tags = String.Join(", ", postDto.Tags.Select(p => p.Name).ToArray()); + Post.Url = WebUtility.UrlDecode(Post.Url); return Page(); } @@ -60,7 +61,7 @@ namespace Volo.Blogging.Pages.Blog.Posts { BlogId = Post.BlogId, Title = Post.Title, - Url = Post.Url, + Url = WebUtility.UrlEncode(Post.Url), CoverImage = Post.CoverImage, Content = Post.Content, Tags = Post.Tags, diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/New.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/New.cshtml.cs index e377a006a3..3f4ff6a036 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/New.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/New.cshtml.cs @@ -66,6 +66,9 @@ namespace Volo.Blogging.Pages.Blog.Posts Post.Description = Post.Content.Truncate(PostConsts.MaxSeoFriendlyDescriptionLength); } + // Url encode the url + Post.Url = WebUtility.UrlEncode(Post.Url); + var postWithDetailsDto = await _postAppService.CreateAsync(ObjectMapper.Map(Post)); //TODO: Try Url.Page(...) From e33b81ba74ff9697deb0b1507ff9b246cba1695d Mon Sep 17 00:00:00 2001 From: Engincan VESKE Date: Fri, 17 Feb 2023 06:53:36 +0000 Subject: [PATCH 2/2] Update New.cshtml.cs --- .../src/Volo.Blogging.Web/Pages/Blogs/Posts/New.cshtml.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/New.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/New.cshtml.cs index 3f4ff6a036..396e225727 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/New.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/New.cshtml.cs @@ -66,7 +66,6 @@ namespace Volo.Blogging.Pages.Blog.Posts Post.Description = Post.Content.Truncate(PostConsts.MaxSeoFriendlyDescriptionLength); } - // Url encode the url Post.Url = WebUtility.UrlEncode(Post.Url); var postWithDetailsDto = await _postAppService.CreateAsync(ObjectMapper.Map(Post));