Thanks for quick response - as you suggested I added a separate controller and made this the default controller. Including my code here for future reference!
public class AuthorisedUmbracoController : RenderMvcController
{
public override ActionResult Index(RenderModel model)
{
var ticket = new System.Web.HttpContextWrapper(System.Web.HttpContext.Current).GetUmbracoAuthTicket();
if (ticket != null)
{
var current = ApplicationContext.Services.UserService.GetByUsername(ticket.Name);
return base.Index(model);
}
//get return URL, check local
var returnUrl = Request.Url.PathAndQuery; // assuming deployed at root)
if (!Url.IsLocalUrl(returnUrl))
{
returnUrl = "/umbraco"; //login screen
}
return new RedirectResult("/umbraco#/login/false?returnPath=" + returnUrl, false);
}
}
The following sets the new controller as the default.
public class ApplicationStartingEventHandler : ApplicationEventHandler
{
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
DefaultRenderMvcControllerResolver.Current.SetDefaultControllerType(typeof(AuthorisedUmbracoController));
}
}
Restrict access to backoffice users
Does anyone know of any way to restrict access to the Umbraco site - to only those users who are logged in to the backoffice?
We're setting up an internal site and want to lock the whole site down to the backoffice users (also authors).
Hi Dave
You can add checking in the master template or render controller is current customer authenticated user or no.
How to get current authenticated user look in this topic - https://our.umbraco.org/forum/developers/api-questions/50075-how-to-get-the-current-user-with-UserService
Thanks,
Alex
Hi Alex,
Thanks for quick response - as you suggested I added a separate controller and made this the default controller. Including my code here for future reference!
The following sets the new controller as the default.
Thanks for your help!
What a great solution, glad that you solved it!
Have a nice evening.
Alex
is working on a reply...