DefaultRenderController and route hijacking
# help-with-umbraco
i
I've created a BaseRenderController and set it using: services.Configure(c => { c.DefaultControllerType = typeof(BaseRenderController); }); the code within the BaseRenderController is being hit only on pages where we DONT use a hijacked route controller. Is this the expected behaviour? I've tried inheriting from RenderController (umbraco) and our BaseRenderController, but at no time can I step through the code in the BaseRenderController.
m
You are replacing the default controller, then overriding it with a controller for that document type when hijacking
You could have your hijacked routes inhiert your base controller
i
@Matt Wise I've tried that with: public class SurveyPageController : BaseRenderController but it doesn't seem to work
public class BaseRenderController : RenderController { private readonly ILogger _logger; private readonly IMemberExtensionsService _memberExtensionsService; public BaseRenderController( ILogger logger, ICompositeViewEngine compositeViewEngine, IUmbracoContextAccessor umbracoContextAccessor, IMemberExtensionsService memberExtensionsService) : base(logger, compositeViewEngine, umbracoContextAccessor) { _logger = logger; _memberExtensionsService = memberExtensionsService; } public override IActionResult Index() { try { // code removed } catch (Exception ex) { _logger.Log(LogLevel.Error, ex.Message, ex); } return CurrentTemplate(CurrentPage); } }
m
On your page controller does it have index or a template name function as that would get called instead of Index on base
i
[SurveyPrivilegeFilter] public class SurveyPageController : BaseRenderController { private readonly ILogger _logger; private readonly IFormService _formService; private readonly IVariationContextAccessor _variationContextAccessor; private readonly ServiceContext _serviceContext; private readonly IPublishedUrlProvider _publishedUrlProvider; private readonly IUmbracoContextAccessor _umbracoContextAccessor; public SurveyPageController( ILogger logger, IFormService formService, ICompositeViewEngine compositeViewEngine, IUmbracoContextAccessor umbracoContextAccessor, IVariationContextAccessor variationContextAccessor, ServiceContext context, IPublishedUrlProvider publishedUrlProvider, IMemberExtensionsService memberExtensionsService) : base(logger, compositeViewEngine, umbracoContextAccessor, memberExtensionsService) { _logger = logger; _formService = formService; _variationContextAccessor = variationContextAccessor; _serviceContext = context; _publishedUrlProvider = publishedUrlProvider; _umbracoContextAccessor = umbracoContextAccessor; } public override IActionResult Index() { var viewModel = new SurveyPage(CurrentPage, new PublishedValueFallback(_serviceContext, _variationContextAccessor)); var id = HttpContext.Request.Query["id"]; var valid = Guid.TryParse(id, out Guid formId); if (!valid) { return new RedirectToUmbracoPageResult(CurrentPage.Parent, _publishedUrlProvider, _umbracoContextAccessor); } viewModel.FormId = formId.ToString(); viewModel.FormName = _formService.Get(formId)?.Name; // return a 'model' to the selected template/view for this page. return CurrentTemplate(viewModel); } }
m
So that should go into SurveyPageController from my understanding
i
Yep, so whenever I load the SurveyPage, I can only step through the code in the SurveyPage render controller, and never in the BaseRender, which seems odd?
m
Id expect it to go into the contstructor but it shouldnt call Index on teh BaseRender unless you call it from the SurveyPage
As you are overriding it
k
You are subclassing
BaseRenderController
, but overriding
Index
. So BRC's constructor will run, but not its
Index
. But what is your intention regarding the base render controller vs the specific controllers? Do you want BRC to be involved every time?
i
Yeah, I was hoping to have the code in the BRC run "every" time for all controllers, but then be able to route hijack on the SurveyPage. Looks like I'll need to move the code in the BRC into a filter, and add that to all render controllers as well as the BRC
k
Couldn't SPC.Index just base.Index? Unless BRC.Index does something strange.
6 Views