Click here to Skip to main content
16,020,714 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have this function in asp.net website
i want to convert it in microsoft Enterprise library.

C#
private void createCookie()
    {
        try
        {
            bool createPersistentCookie = true;
            string username = txtemailID.Text;
            string pass = txtpwd.Text;

            FormsAuthentication.Initialize();
            ////HttpCookie cookie = new HttpCookie("UserName");
            ////cookie.Value = username;
            ////cookie.Expires = DateTime.Now.AddDays(1);
            //////cookie["username"] = username;
            ////Response.Cookies.Add(cookie);
            ////string ckValue = Request.Cookies["UserName"].Value;
            HttpCookie cookie = FormsAuthentication.GetAuthCookie(username, createPersistentCookie);
            var time = DateTime.Now.AddDays(1);
            cookie.Expires = time;
            var userData = username;
            var cookieVal = FormsAuthentication.Decrypt(cookie.Value);

            FormsAuthenticationTicket aticket = new FormsAuthenticationTicket(cookieVal.Version, cookieVal.Name, cookieVal.IssueDate, time, true, userData);
            cookie.Value = FormsAuthentication.Encrypt(aticket);
            HttpContext.Current.Response.Cookies.Add(cookie);
            //HttpContext.Current.Response.Cookies.Set(cookie);
            string ckValue = null;
            //string userId = null;
            //if (this.Context.User.Identity.IsAuthenticated)
            //    userId = this.Context.User.Identity.Name;
            if (cookie != null)
            {
                ckValue = cookie.Value;//Server.HtmlEncode(cookie.Value) ;
                Response.Write(cookie.Value);
                //Session["user"] = ckValue;
            }
            //return aticket.UserData;
            FormsAuthentication.RedirectFromLoginPage("UserPost.aspx", true);
        }
        catch (Exception ex)
        {
            FormsAuthentication.SetAuthCookie(userName, createPersistentCookie);
        }
        //return aticket.UserData;
        
    }
Posted
Updated 9-Aug-12 20:02pm
v2
Comments
niki_nilu 10-Aug-12 6:37am    
i think no one know about the Enterprise library

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900