November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
I don't think model is a valid dictionary value. It expects a controller and action.
Can you try something like this?
new RedirectToAction("ControllerName","ActionName", model);
One option could be to do the redirection earlier during routing (instead of in an action filter). You could for example attach an event handler for EPiServer.Web.Routing.IContentRouteEvents.RoutedContent. The event argument has a property RoutingSegmentContext which have a RoutedContentLink property that specifies which content that the request have been routed to.
So what you could do is to check if that content has expired and if so call method PermanentRedirect() (or TemporaryRedirect) that are methods on RoutingSegmentContext property on event args.
Hello again everyone.
Finally it works, thanks to all for your support, was very helpful, this is what I did to do it works:
On my PageControllerBase (or BaseController) I did the Follow:
protected override void OnAuthorization(AuthorizationContext filterContext) { // don't throw 404 in edit mode if (!PageEditing.PageIsInEditMode) { if (PageContext?.Page != null && PageContext.Page.StopPublish <= DateTime.Now) { if (PageContext.Page.PageTypeName == "SpecialistPage") { IContentRepository cr = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentRepository>(); SiteSettingsPage childPages = cr.GetChildren<SiteSettingsPage>(ContentReference.StartPage).FirstOrDefault(); IContentRepository factory = DataFactory.Instance; UitDienstPage specialistVerlopenPage = factory.Get<UitDienstPage>(childPages.SpecialistVerlopenPage); if (specialistVerlopenPage != null) { filterContext.Result = this.RedirectToAction("SpecialistVerlopen", "UitDienstPage", specialistVerlopenPage); return; } } else { filterContext.Result = new HttpStatusCodeResult(404, "Not found"); return; } } else { //If the page is not expired, then go ahead... base.OnAuthorization(filterContext); } } else { base.OnAuthorization(filterContext); } } private new RedirectToRouteResult RedirectToAction(string action, string controller, UitDienstPage model) { TempData["TempSpecialistVerlopenPage"] = model; return base.RedirectToAction(action, controller, new { node = model.ContentLink }); }
And also I have created a new Controller to call and render my VewModel:
public class UitDienstPageController : PageControllerBase<UitDienstPage> { // GET: UitDienstPage public ViewResult SpecialistVerlopen() { UitDienstPage model = (UitDienstPage)TempData["TempSpecialistVerlopenPage"]; var viewModel = new UitDienstPageViewModel(model); return View("~/Views/Pages/UitDienstPage.cshtml", viewModel); } }
This have worked for me.
Do you see guys another way to accomplish this?
or
Do you see anything weird/strange on my code?
Best regards.
Hi,
finally I made a new change that looks more clean and efficiently.
On my PageControllerBase (or BaseController) I did the Follow:
protected override void OnAuthorization(AuthorizationContext filterContext) { // don't throw 404 in edit mode if (!PageEditing.PageIsInEditMode) { if (PageContext?.Page != null && PageContext.Page.StopPublish <= DateTime.Now) { if (PageContext.Page.PageTypeName == "SpecialistPage") { IContentRepository cr = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentRepository>(); SiteSettingsPage childPages = cr.GetChildren<SiteSettingsPage>(ContentReference.StartPage).FirstOrDefault(); IContentRepository factory = DataFactory.Instance; UitDienstPage specialistVerlopenPage = factory.Get<UitDienstPage>(childPages.SpecialistVerlopenPage); if (specialistVerlopenPage != null) { filterContext.Result = Redirect(UrlResolver.Current.GetUrl(specialistVerlopenPage.ContentLink)); return; } } else { filterContext.Result = new HttpStatusCodeResult(404, "Not found"); return; } } else { //If the page is not expired, then go ahead... base.OnAuthorization(filterContext); } } else { base.OnAuthorization(filterContext); } }
An also I have removed the method and the new controller "UitDienstPageController" because I don't going to us it anymore.
private new RedirectToRouteResult RedirectToAction(string action, string controller, UitDienstPage model) { TempData["TempSpecialistVerlopenPage"] = model; return base.RedirectToAction(action, controller, new { node = model.ContentLink }); }
I hope this post could help to more people with the same problem.
Thank you everyone for your help and support.
Best regards.
Hello everyone.
I'm trying to do something that I'm not completly sure if I can do.
I have a Page that is Expired (Expiration Date added in the Epi CMS). the idea is that when a user will try to access this page be redirected to another Page automatically.
For do this I have this code on my PageControllerBase (or BaseController):
I don't know what I'm doing wrong.
Could anyone explain me how to do that and why my code is not working properly?.
Best regards.