This .net 6 library contains a RedirectManager and admin user interface integration in an Optimizely CMS 12 and commerce 14 project. Tested with Alloy.
An Optimizely addon that helps with managements of redirects. Simple but yet so effective. It is based out of https://github.com/huilaaja/RedirectManager
This is the .net 6 version of : https://github.com/huilaaja/RedirectManager <-- use this for CMS 11
Preview:
Preview:
Available on nuget.optimizely.com https://nuget.optimizely.com/package/?id=Epicweb.Optimizely.RedirectManager
Start by installing NuGet package:
Install-Package Epicweb.Optimizely.RedirectManager
Add to startup.cs
services.AddRedirectManager(
addQuickNavigator: true,
enableChangeEvent: true);
also
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
//remember if you use env.IsDevelopment() do activate error pages in dev env too
//do NOT use => app.UseStatusCodePagesWithRedirects("/Error/{0}");//not redirects
app.UseStatusCodePagesWithReExecute("/Error/{0}");
app.UseExceptionHandler("/Error/500");
}
Run your application
First time, you will be prompted to create the redirect table "SEO_redirect"
That should not be a problem. If you used the Solita solution, change the name of the table "SOLITA_Redirect" to "SEO_Redirect", should be the same schema if you run on latest solution, make sure you have run this V2 upgrade before, (or added the host column manually) [https://github.com/huilaaja/RedirectManager/blob/c7ec6ea4b12aa36b53b27fa89bb373286fe0d53d/WebProject/Redirects/RedirectService.cs#L282]
Schema should look like this:
add this code into your error/404 custom page controller
#region RedirectManager
if (statusCode == 404)
{
string originalRelativePath = HttpContext.Request.GetRawUrl();//get current url
string redirectTo = _redirectService.GetPrimaryRedirectUrlOrDefault(SiteDefinition.Current.Name, originalRelativePath);//check if redirect rule exists
if (redirectTo != null)
{
Response.Redirect(redirectTo, true);
}
}
#endregion
using Epicweb.Optimizely.RedirectManager;
using EPiServer.Web;
using Microsoft.AspNetCore.Mvc;
namespace Epicweb.Optimizely.Blog.Features.Error
{
public class ErrorController : Controller
{
private readonly IContentRepository _contentRepository;
private readonly RedirectService _redirectService;
public ErrorController(IContentRepository contentRepository, RedirectService redirectService)
{
_contentRepository = contentRepository;
_redirectService = redirectService;
}
[Route("/Error/{statusCode}")]
public IActionResult HttpStatusCodeHandler(int statusCode)
{
ViewBag.Code = statusCode;
//this is specific redirectManager
#region RedirectManager
if (statusCode == 404)
{
string originalRelativePath = HttpContext.Request.GetRawUrl();//get current url
string redirectTo = _redirectService.GetPrimaryRedirectUrlOrDefault(SiteDefinition.Current.Name, originalRelativePath);//check if redirect rule exists
if (redirectTo != null)
{
Response.Redirect(redirectTo, true);
}
}
#endregion
return View("~/Features/Error/Error.cshtml");
}
}
}
Users with role WebAdmins and RedirectManagers will automatically see the menu in Optimizely CMS
Get this solution runing
Clone it
Unpack the /alloy/app_data/blobs-and-database.zip
dotnet run
log in to CMS with "admin" and "Test1234!"