Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Simon 48 posts 108 karma points
    May 31, 2018 @ 15:11
    Simon
    0

    Backoffice user not logged in on front end

    Using the code below to retrieve the current backoffice user, the user appears to be logged in within the view of the backoffice but not logged in on the front end.

    public static IUser GetCurrentUser() {
        string userName = "";
        var auth = new HttpContextWrapper(HttpContext.Current).GetUmbracoAuthTicket();
    
        if (auth != null) {
            userName = auth.Name;
        }
    
        return ApplicationContext.Current.Services.UserService.GetByUsername(userName);
    }
    

    The function is called from a custom dashboard.aspx file and when it displays in the backoffice the user details available but not when the dashboard.aspx file is called directly through the browser. Relevant lines from dashboard.aspx:

    protected void Page_Load(object sender, EventArgs e) {
        var CurrentUser = Helpers.CustomUmbracoHelper.GetCurrentUser();
    
        if (CurrentUser != null) {
            // 1 is admin type, 5 is site admin type
            if (CurrentUser.UserType.Id == 1 || CurrentUser.UserType.Id == 5) {
                // ok to proceed
                pnlAdminView.Visible = true;
                pnlNonAdminView.Visible = false;
            }
        }
    }
    

    I should mention that this same code is working on another site and this is a slightly modified version of that site.

  • Paul Seal 524 posts 2889 karma points MVP 7x c-trib
    May 31, 2018 @ 15:46
    Paul Seal
    0

    Hi Simon

    I'm not sure exactly what you're doing here, but maybe this will help you.

    https://codeshare.co.uk/blog/how-to-get-the-current-logged-in-umbraco-user-and-restrict-front-end-content/

    Kind regards

    Paul

  • Simon 48 posts 108 karma points
    Jun 01, 2018 @ 19:51
    Simon
    0

    Your link is only a rehash of the code I'm already using.

  • Simon 48 posts 108 karma points
    Jun 01, 2018 @ 19:50
    Simon
    0

    Still seeing the same issue. I took at the log and I'm seeing something that might be causing the issue... but not sure what's causing that or the fix. Here's the log entries:

    2018-06-01 15:46:53,653 [P22024/D2/T20] ERROR Umbraco.Core.Security.AuthenticationExtensions - The current identity cannot be converted to Umbraco.Core.Security.UmbracoBackOfficeIdentity System.InvalidOperationException: Cannot create a Umbraco.Core.Security.UmbracoBackOfficeIdentity from System.Security.Claims.ClaimsIdentity since the required claim http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier is missing at Umbraco.Core.Security.UmbracoBackOfficeIdentity.FromClaimsIdentity(ClaimsIdentity identity) at Umbraco.Core.Security.AuthenticationExtensions.GetCurrentIdentity(HttpContextBase http, Boolean authenticateRequestIfNotFound)

    2018-06-01 15:47:01,238 [P22024/D2/T20] ERROR Umbraco.Web.WebApi.Filters.AngularAntiForgeryHelper - Could not validate XSRF token System.Web.Mvc.HttpAntiForgeryException (0x80004005): The anti-forgery token could not be decrypted. If this application is hosted by a Web Farm or cluster, ensure that all machines are running the same version of ASP.NET Web Pages and that the

  • Simon 48 posts 108 karma points
    Jun 05, 2018 @ 15:03
    Simon
    0

    Any ideas?

  • Simon 48 posts 108 karma points
    Jun 14, 2018 @ 15:30
    Simon
    0

    Bump

Please Sign in or register to post replies

Write your reply to:

Draft