Copied to clipboard

Flag this post as spam?

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


  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jun 21, 2011 @ 11:54
    Lee Kelleher
    0

    Auto-login member (front-end)

    With Umbraco 4.7 is it possible to auto login a member - to access a protected area?

    My main issue is that I previous had a working solution with Umbraco 4.0.x - using a code snippet from this forum post: Auto-login as a member for Google Mini Search

    Using this to inherit/override the "default.aspx" / "umbraco.UmbracoDefault" page/class:

    protected void Page_Init(object sender, EventArgs e)
    {
        if (!umbraco.library.IsLoggedOn())
        {
            // check if UserAgent contains a specific string
            if (Request.UserAgent.Contains("***hidden***")
            {
                // Auto Login
                var m = Member.GetMemberFromEmail("[email protected]");
                Member.AddMemberToCache(m, true, TimeSpan.FromHours(1));
                Response.Redirect(Request.RawUrl, true);
            }
        }
    }

    But, this no longer seems to work in Umbraco v4.7 (after an upgrade).

    Thinking that it's most likely a cookie related issue - either with Umbraco or the MembershipProvider?

    Any ideas, suggestions? I'd really appreciated it - starting to pull my hair out with this! :-$

    Thanks, Lee.

  • Mads Krohn 211 posts 504 karma points c-trib
    Jun 21, 2011 @ 12:28
    Mads Krohn
    1

    Hey Lee

    I'm pretty sure that Umbraco 4.5.x and up uses the .net built-in membership stuff per default.
    This means, that you should try and use the native membership functions, I at least, have had great success with it so far.

    I havent testet this exact code, but you should be able to do something like this in your auto login part:

    var member = Membership.GetUserNameByEmail(email);
    var ticket = new FormsAuthenticationTicket(string name, bool isPersistent, int timeout);
    var encryptedTicket = FormsAuthentication.Encrypt(ticket); 
    var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket) { Expires = ticket.Expiration };
    Response.Cookies.Add(authCookie); 
    Response.Redirect(Request.RawUrl, true); 

    Hope this can help you :)

    /Mads

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jun 21, 2011 @ 13:23
    Lee Kelleher
    0

    Thanks Mads!

    Seems it was a different issue... my Web.config was missing the "cookieless=UseCookies" attribute for "system.web/authentication/forms"

    <authentication mode="Forms">
    <forms name="yourAuthCookie" loginUrl="login.aspx" protection="All" path="/" cookieless="UseCookies" />
    </authentication>

    After that, my original code works fine!

    Cheers, Lee.

    I'm setting the AuthCookie manually - just in case - thanks for the tip!

Please Sign in or register to post replies

Write your reply to:

Draft