From 22932675c47968716cf126dbe0e146341ba01706 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Wed, 25 Dec 2019 11:12:47 +0300 Subject: [PATCH] blogging redirect urls --- .../Controllers/HomeController.cs | 11 ++++++++++- .../Volo.Blogging.Web/Pages/Blog/Posts/New.cshtml.cs | 8 ++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/modules/blogging/app/Volo.BloggingTestApp/Controllers/HomeController.cs b/modules/blogging/app/Volo.BloggingTestApp/Controllers/HomeController.cs index 0e4a7acc1d..f64a1da5ae 100644 --- a/modules/blogging/app/Volo.BloggingTestApp/Controllers/HomeController.cs +++ b/modules/blogging/app/Volo.BloggingTestApp/Controllers/HomeController.cs @@ -1,13 +1,22 @@ using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; using Volo.Abp.AspNetCore.Mvc; +using Volo.Blogging; namespace Volo.BloggingTestApp.Controllers { public class HomeController : AbpController { + private readonly BloggingUrlOptions _blogOptions; + + public HomeController(IOptions blogOptions) + { + _blogOptions = blogOptions.Value; + } public ActionResult Index() { - return Redirect("/blog/"); + var urlPrefix = _blogOptions.RoutePrefix; + return Redirect(urlPrefix); } } } diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/New.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/New.cshtml.cs index ad2dbc846f..b566b7bbe0 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/New.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/New.cshtml.cs @@ -4,6 +4,7 @@ using System.Net; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; using Volo.Blogging.Blogs; using Volo.Blogging.Blogs.Dtos; @@ -16,6 +17,7 @@ namespace Volo.Blogging.Pages.Blog.Posts private readonly IPostAppService _postAppService; private readonly IBlogAppService _blogAppService; private readonly IAuthorizationService _authorization; + private readonly BloggingUrlOptions _blogOptions; [BindProperty(SupportsGet = true)] public string BlogShortName { get; set; } @@ -25,11 +27,12 @@ namespace Volo.Blogging.Pages.Blog.Posts public BlogDto Blog { get; set; } - public NewModel(IPostAppService postAppService, IBlogAppService blogAppService, IAuthorizationService authorization) + public NewModel(IPostAppService postAppService, IBlogAppService blogAppService, IAuthorizationService authorization, IOptions blogOptions) { _postAppService = postAppService; _blogAppService = blogAppService; _authorization = authorization; + _blogOptions = blogOptions.Value; } public async Task OnGetAsync() @@ -54,7 +57,8 @@ namespace Volo.Blogging.Pages.Blog.Posts var postWithDetailsDto = await _postAppService.CreateAsync(ObjectMapper.Map(Post)); //TODO: Try Url.Page(...) - return Redirect(Url.Content($"~/blog/{WebUtility.UrlEncode(blog.ShortName)}/{WebUtility.UrlEncode(postWithDetailsDto.Url)}")); + var urlPrefix = _blogOptions.RoutePrefix; + return Redirect(Url.Content($"~{urlPrefix}{WebUtility.UrlEncode(blog.ShortName)}/{WebUtility.UrlEncode(postWithDetailsDto.Url)}")); } public class CreatePostViewModel