iServe.Models.User.ToDelimitedString C# (CSharp) Method

ToDelimitedString() public method

public ToDelimitedString ( ) : string
return string
        public string ToDelimitedString()
        {
            StringBuilder output = new StringBuilder();

            //User user = new User{ ID=1, ChurchID=1, Name, Email, Rating}
            output.Append(ID);
            output.Append("~").Append(ChurchID);
            output.Append("~").Append(Name);
            output.Append("~").Append(Email);
            output.Append("~").Append(Rating);

            return output.ToString();
        }

Usage Example

Ejemplo n.º 1
0
        private void WriteAuthCookie(User user)
        {
            //int userID, string username) {
            double formsAuthTimeout = 40;
            string userData = user.ToDelimitedString();

            FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(
                                                            1,				// version
                                                            user.Name,		// user name
                                                            DateTime.Now,	// creation
                                                            DateTime.Now.AddMinutes(formsAuthTimeout),  // Expiration
                                                            false,			// isPersistent
                                                            user.ToDelimitedString() // user data (just user object in simple delimited string)
                                                            );
            string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
            HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);

            // Make sure we mark the cookie as "Secure" if RequireSSL is set in the web.config.
            //  If we don't, the FIRST issuing of this cookie will not be secure
            //  (as we are the ones that did it) while the second issuing (when it's
            //  being refreshed) will be secure. That would cause intermittent problems with
            //  timeout-like behaviors around "timeout/2" minutes into the user's session.
            authCookie.Secure = FormsAuthentication.RequireSSL;
            authCookie.HttpOnly = true;
            HttpContext.Response.Cookies.Add(authCookie);
        }