Browse Source

Redirect to true URL.

pull/15/head
Halil İbrahim Kalkan 6 years ago
parent
commit
20da0d7254
  1. 24
      eventhub/src/EventHub.Web/Pages/Events/Detail.cshtml.cs

24
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<IActionResult> 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();
}
}
}

Loading…
Cancel
Save