Copied to clipboard

Flag this post as spam?

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


  • Antony Wong 14 posts 43 karma points
    Oct 09, 2014 @ 18:04
    Antony Wong
    0

    Role based Authentication

    Hi

    I have a few pages setup using role protection. However, the site cant be using cookies. Is there a way to login the user and gain access to the role based protection pages?

    I have set the ticket by using the code (Displayed below). It logs in fine but as soon as i get redirected to a page that has protection on it, it logs me out.

            ticket = new FormsAuthenticationTicket(2, model.Username, DateTime.UtcNow, DateTime.UtcNow.AddMinutes(int.Parse(ConfigurationManager.AppSettings["TicketTimeout"])), false, Guid.NewGuid().ToString());
    
            if (ticket == null)
            {
                throw new Exception("Error creating authentication ticket");
            }
    
            // Encrypt the ticket.
            EncryptedTicket = FormsAuthentication.Encrypt(ticket);
    
            HttpContext.Current.User = new GenericPrincipal(new FormsIdentity(ticket), Roles.GetRolesForUser(model.Username));
            var member = Member.GetMemberFromLoginName(model.Username);
    
            if (member == null)
            {
                throw new Exception("Error getting member from Umbraco");
            }
    
  • Damian Green 452 posts 1433 karma points
    Oct 09, 2014 @ 22:50
    Damian Green
    0

    Hi Antony,

    When you say "the site cant be using cookies" do you mean you want a cookieless session - or the site doesn't appear to be creating a cookie when it should be?

    Damian

  • Antony Wong 14 posts 43 karma points
    Oct 09, 2014 @ 23:59
    Antony Wong
    0

    Hi The site is not using cookies, so I am creating a ticket and authenticating the user and storing it in cache. It works fine for document types that not protected. However, with protected it logs me straight out.

    If i add the code FormsAuthentication.SetAuthCookie(). It works fine,

    Is there something I am missing?

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies