Exemplo n.º 1
0
        /// <summary>
        /// Sets an encrypted cookie for the user.  Cookie contains user name, user type and city/customer
        /// </summary>
        /// <param name="value"></param>
        protected void SetCityCookie(string value)
        {
            //cookie will be username|cityinternalname|loginType so "Bob|Admin|Customer" or "Bob|NorthSydneyCouncil|Maintenance"
            //remove the cookie if it already exists
            DeleteCityCookie();

            //now add the new one
            var cookie = new HttpCookie(Constants.Security.UserCityCookieName, value);
            //var strCookieExpMinutes = ConfigurationManager.AppSettings[Constants.Security.CityCookieExpirationAppSettingName];
            //int cookieExpInMinutes;
            //int.TryParse(strCookieExpMinutes, out cookieExpInMinutes);
            ////default it to an hour if this is not set correctly
            //if (cookieExpInMinutes < 1)
            //    cookieExpInMinutes = 60;
            HttpCookie encodedCookie = CookieManager.Encode(cookie);

            // encodedCookie.Expires = DateTime.Now.AddMinutes(cookieExpInMinutes);
            Response.Cookies.Add(encodedCookie);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Deletes the users city cookie.
 /// </summary>
 public void DeleteCityCookie()
 {
     //check to see if the user is logged in, and if they are, set it to name|none|Customer, otherwise expire the cookie
     if (User.Identity.IsAuthenticated)
     {
         //default it to the customer login
         var cookie = new HttpCookie(Constants.Security.UserCityCookieName,
                                     User.Identity.Name + "|None|" + CustomerLoginType.Unknown);
         HttpCookie encodedCookie = CookieManager.Encode(cookie);
         Response.Cookies.Set(encodedCookie);
     }
     else
     {
         var cookie = new HttpCookie(Constants.Security.UserCityCookieName)
         {
             Expires = DateTime.Now.AddDays(-1)     // or any other time in the past
         };
         Response.Cookies.Set(cookie);
     }
 }