In my JSON controller I want to check the access right from the User.
My code looks like this
public class MyController : SitecoreController
{
public static bool CheckAccessRight()
{
if (Sitecore.Context.User.IsInRole("sitecore\\Sitecore Client Users"))
{
return true;
}
if (Sitecore.Context.User.IsAdministrator)
{
return true;
}
return false;
}
[System.Web.Http.HttpGet, System.Web.Http.HttpPost]
public ActionResult DoSomethings(int page)
{
if (!CheckAccessRight())
{
return new JsonResult { Data = "access denied", JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
return new JsonResult { Data = "my data", JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
}
The controller is registered in the initialize Pipeline. simiar to the documentation https://doc.sitecore.com/developers/91/sitecore-experience-management/en/use-mvc-routing.html. Works on older versions of Sitecore but in Sitecore 9.1 update-1 the Sitecore.Context.User
gives not the logged in user but gives
extranet\Anonymous
How can I get the actual user back?
Note: it fails in Sitecore 9.1 initial version and Sitecore 9.1 update-1. works on 9.0