From 20da0d72545bca4a234b81ebbcba7e3bf87cba47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sun, 24 Jan 2021 13:54:18 +0300 Subject: [PATCH] Redirect to true URL. --- .../Pages/Events/Detail.cshtml.cs | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/eventhub/src/EventHub.Web/Pages/Events/Detail.cshtml.cs b/eventhub/src/EventHub.Web/Pages/Events/Detail.cshtml.cs index 7a7f729..d286a21 100644 --- a/eventhub/src/EventHub.Web/Pages/Events/Detail.cshtml.cs +++ b/eventhub/src/EventHub.Web/Pages/Events/Detail.cshtml.cs @@ -2,6 +2,7 @@ using EventHub.Events; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Routing; namespace EventHub.Web.Pages.Events { @@ -13,17 +14,36 @@ namespace EventHub.Web.Pages.Events public EventDetailDto Event { get; set; } private readonly IEventAppService _eventAppService; + private readonly LinkGenerator _linkGenerator; - public Detail(IEventAppService eventAppService) + public Detail( + IEventAppService eventAppService, + LinkGenerator linkGenerator) { _eventAppService = eventAppService; + _linkGenerator = linkGenerator; } - public async Task OnGetAsync() + public async Task OnGetAsync() { var urlCode = EventUrlCodeHelper.GetCodeFromUrl(Url); Event = await _eventAppService.GetByUrlCodeAsync(urlCode); + + if (Event.Url != Url) + { + return RedirectPermanent( + _linkGenerator.GetPathByPage( + "/Events/Detail", + values: new + { + url = Event.Url + } + ) + ); + } + + return Page(); } } }