Spark CustomPrincipal is null for some requests?
In the Spark 4.5 Art solution, has anyone run into the problem where the CustomPrincipal properties are NULL for some requests? I first noticed this with the ChangeAccount action method in the AuthController where the CurrentUser.Id property was null. Interestingly GET requests it seems to be fine (see attached screenshots).
// This results in a NULL user because the CurrentUser.Id property is null
// for the ChangeAccount action method in the AuthController.
var user = PeerReviewContext.Users.Single(CurrentUser.Id);
I did some testing and for GET requests System.Threading.Thread.CurrentPrincipal is CustomPrincipal is true, but it's false for POST requests.
I thought it might be something I had done to the solution so I deleted the local installation and unzipped it again from the source, but the issues persists.
Anyone else experiencing this, and better yet, do you know what the issue is?
Mark Erasmus, Sep 05, 2015
Anyone else experiencing this?
Sep 16, 2015
My fix for this was assigning HttpContext.Current.User = customPrincipal; in the Application_PostAuthenticateRequest() method in the global.ascx, instead of assigning it to the current thread's principal. Using the current thread's principal just wasn't a reliable approach since I was intermittently getting nulls back for the CurrentUser properties for identical request. Obviously I had to update the CurrentUser class to use HttpContext.Current.User, rather than Thread.Current.Principal.
Mark Erasmus, Sep 17, 2015