Default Custom Controller & Having An Action On All Pages
Hi there
I have read and successfully implemented a default custom controller and I "hit" the controller when viewing pages where there is no associated page controller.
However the site I am building needs some functionality to run on all pages, and whilst I can add the logic to all page controllers as required, I wondered if there is a way to have it fire automatically on all pages ?
Re the BaseContoller controller idea - so conceptually a Base Controller that inherits from RenderMVCController, with the individual controllers inheriting from the Base Controller ?
Sorry but it seems my excitement was a bit premature.
Below is my base controller, but this is now creating a YSOD - when revert to "standard" umbraco controller code the site runs up fine.
public class BaseController : RenderMvcController
{
protected override void Initialize(RequestContext requestContext)
{
//TODO - write Umbraco helper to get home page
//TODO - write logic to check user
}
}
Can anyone enlighten as to how to create a BaseController that inherits from RenverMvController?
I had left out the base.Initialize(requestContext) line, but both methods above are hit when debugging, so the train is back on the tracks and about to get a hot of coal - full steam ahead... :-)
Default Custom Controller & Having An Action On All Pages
Hi there
I have read and successfully implemented a default custom controller and I "hit" the controller when viewing pages where there is no associated page controller.
However the site I am building needs some functionality to run on all pages, and whilst I can add the logic to all page controllers as required, I wondered if there is a way to have it fire automatically on all pages ?
Thanks
Nigel
Hi Nigel,
thought on creating a base controller that you can use for all your pages to inherit from?
Or maybe try to implement an ActionFilter which runs on each request.
Regards David
Hi David
Thanks for your thoughts - appreciate it.
ActionFilters are new to me so will investigate.
Re the BaseContoller controller idea - so conceptually a Base Controller that inherits from RenderMVCController, with the individual controllers inheriting from the Base Controller ?
Cheers
Nigel
Hi Nigel,
the ActionFilter stuff is quite nice to handle things that should be run on each request. Depends on what you are trying to accomplish.
Yes exactly, create a BaseController which inherits from RenderMvcController and then let all your custom controller inherit from that BaseController.
Regards David
Hi David
Added the base controller logic last night and it is working a treat so far.
APpreciate your feedback / help. Will still have a look at ActionFilters too - always good to know about other options.
Cheers, Nigel
David
Sorry but it seems my excitement was a bit premature.
Below is my base controller, but this is now creating a YSOD - when revert to "standard" umbraco controller code the site runs up fine.
Can anyone enlighten as to how to create a BaseController that inherits from RenverMvController?
Thanks Nigel
Hi Nigel,
what is the error message in the YSOD?
Regards David
Hey David
OK, things are working now with updated code as below.
I had left out the base.Initialize(requestContext) line, but both methods above are hit when debugging, so the train is back on the tracks and about to get a hot of coal - full steam ahead... :-)
Cheers, Nigel
is working on a reply...