private static void WriteData(JsonTextWriter writer, FormsModel model)
        {
            writer
            .StartObject()
            .Property("p", model.IsPersistent, true)
            .Property("e", model.ExpireUtc, DateTimeOffset.MinValue)
            .StartArray("i");

            foreach (var identity in model.Principal.Identities)
            {
                writer
                .StartObject()
                .Property("at", identity.AuthenticationType, null)
                .Property("nct", identity.NameClaimType, ClaimsIdentity.DefaultNameClaimType)
                .Property("rct", identity.RoleClaimType, ClaimsIdentity.DefaultRoleClaimType)
                .StartArray("c");

                foreach (var claim in identity.Claims)
                {
                    writer
                    .StartObject()
                    .Property("t", claim.Type, identity.NameClaimType)
                    .Property("v", claim.Value, null)
                    .EndObject();
                }

                writer
                .EndArray()
                .EndObject();
            }
        }
 public static byte[] Serialize(FormsModel model)
 {
     var memory = new MemoryStream();
     using (var writer = new JsonTextWriter(new StreamWriter(memory)))
     {
         WriteData(writer, model);
     }
     return memory.ToArray();
 }
        public static byte[] Serialize(FormsModel model)
        {
            var memory = new MemoryStream();

            using (var writer = new JsonTextWriter(new StreamWriter(memory)))
            {
                WriteData(writer, model);
            }
            return(memory.ToArray());
        }
        private static void WriteData(JsonTextWriter writer, FormsModel model)
        {
            writer
                .StartObject()
                .Property("p", model.IsPersistent, true)
                .Property("e", model.ExpireUtc, DateTimeOffset.MinValue)
                .StartArray("i");

            foreach (var identity in model.Principal.Identities)
            {
                writer
                    .StartObject()
                    .Property("at", identity.AuthenticationType, null)
                    .Property("nct", identity.NameClaimType, ClaimsIdentity.DefaultNameClaimType)
                    .Property("rct", identity.RoleClaimType, ClaimsIdentity.DefaultRoleClaimType)
                    .StartArray("c");

                foreach (var claim in identity.Claims)
                {
                    writer
                        .StartObject()
                        .Property("t", claim.Type, identity.NameClaimType)
                        .Property("v", claim.Value, null)
                        .EndObject();
                }

                writer
                    .EndArray()
                    .EndObject();
            }
        }