blogging redirect urls

pull/2464/head^2
Yunus Emre Kalkan 6 years ago
parent 9809ab992e
commit 22932675c4

@ -1,13 +1,22 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc;
using Volo.Blogging;
namespace Volo.BloggingTestApp.Controllers namespace Volo.BloggingTestApp.Controllers
{ {
public class HomeController : AbpController public class HomeController : AbpController
{ {
private readonly BloggingUrlOptions _blogOptions;
public HomeController(IOptions<BloggingUrlOptions> blogOptions)
{
_blogOptions = blogOptions.Value;
}
public ActionResult Index() public ActionResult Index()
{ {
return Redirect("/blog/"); var urlPrefix = _blogOptions.RoutePrefix;
return Redirect(urlPrefix);
} }
} }
} }

@ -4,6 +4,7 @@ using System.Net;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages;
using Volo.Blogging.Blogs; using Volo.Blogging.Blogs;
using Volo.Blogging.Blogs.Dtos; using Volo.Blogging.Blogs.Dtos;
@ -16,6 +17,7 @@ namespace Volo.Blogging.Pages.Blog.Posts
private readonly IPostAppService _postAppService; private readonly IPostAppService _postAppService;
private readonly IBlogAppService _blogAppService; private readonly IBlogAppService _blogAppService;
private readonly IAuthorizationService _authorization; private readonly IAuthorizationService _authorization;
private readonly BloggingUrlOptions _blogOptions;
[BindProperty(SupportsGet = true)] [BindProperty(SupportsGet = true)]
public string BlogShortName { get; set; } public string BlogShortName { get; set; }
@ -25,11 +27,12 @@ namespace Volo.Blogging.Pages.Blog.Posts
public BlogDto Blog { get; set; } public BlogDto Blog { get; set; }
public NewModel(IPostAppService postAppService, IBlogAppService blogAppService, IAuthorizationService authorization) public NewModel(IPostAppService postAppService, IBlogAppService blogAppService, IAuthorizationService authorization, IOptions<BloggingUrlOptions> blogOptions)
{ {
_postAppService = postAppService; _postAppService = postAppService;
_blogAppService = blogAppService; _blogAppService = blogAppService;
_authorization = authorization; _authorization = authorization;
_blogOptions = blogOptions.Value;
} }
public async Task<ActionResult> OnGetAsync() public async Task<ActionResult> OnGetAsync()
@ -54,7 +57,8 @@ namespace Volo.Blogging.Pages.Blog.Posts
var postWithDetailsDto = await _postAppService.CreateAsync(ObjectMapper.Map<CreatePostViewModel,CreatePostDto>(Post)); var postWithDetailsDto = await _postAppService.CreateAsync(ObjectMapper.Map<CreatePostViewModel,CreatePostDto>(Post));
//TODO: Try Url.Page(...) //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 public class CreatePostViewModel

Loading…
Cancel
Save