Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Url.HasProfile())
            {
                //We got profile
                var profile = Request.Url.GetProfile();
                if (profile.IsAuthorized)
                {
                    //SAMPLE
                    //Do something with it
                    var username = profile.UniqueId;
                    var userData = profile.UserDisplayName;

                    var linker = new Linker(ConfigurationManager.ConnectionStrings["openids"]);
                    var linked = linker.GetLinkedObjects(profile);
                    if (linked.Count() > 0)
                    {
                        //Already has something
                    }
                    else
                    {
                        linker.AddLink("Hellou!!!", profile);
                    }

                    var ticket = new FormsAuthenticationTicket(1,
                                                               username,
                                                               DateTime.Now,
                                                               DateTime.Now.AddMinutes(5),
                                                               false,
                                                               userData,
                                                               FormsAuthentication.FormsCookiePath);
                    // Encrypt the ticket.
                    string encTicket = FormsAuthentication.Encrypt(ticket);
                    // Create the cookie.
                    Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));
                    // Redirect back to original URL.
                    Response.Redirect(FormsAuthentication.GetRedirectUrl(username, false));
                }
                else
                {
                    //Show errors
                    Error = profile.AuthorizationError;
                }
            }
        }