private static string GetEncodedValue(AnonymousIdData data) { if (data == null) { return(null); } byte[] bytes = Encoding.UTF8.GetBytes(data.AnonymousId); byte[] src = BitConverter.GetBytes(bytes.Length); byte[] buffer3 = BitConverter.GetBytes(data.ExpireDate.ToFileTimeUtc()); byte[] dst = new byte[12 + bytes.Length]; Buffer.BlockCopy(buffer3, 0, dst, 0, 8); Buffer.BlockCopy(src, 0, dst, 8, 4); Buffer.BlockCopy(bytes, 0, dst, 12, bytes.Length); return(CookieProtectionHelper.Encode(s_Protection, dst, dst.Length)); }
///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// private static string GetEncodedValue(AnonymousIdData data) { if (data == null) { return(null); } byte [] bufId = Encoding.UTF8.GetBytes(data.AnonymousId); byte [] bufIdLen = BitConverter.GetBytes(bufId.Length); byte [] bufDate = BitConverter.GetBytes(data.ExpireDate.ToFileTimeUtc()); byte [] buffer = new byte[12 + bufId.Length]; Buffer.BlockCopy(bufDate, 0, buffer, 0, 8); Buffer.BlockCopy(bufIdLen, 0, buffer, 8, 4); Buffer.BlockCopy(bufId, 0, buffer, 12, bufId.Length); return(CookieProtectionHelper.Encode(s_Protection, buffer, Purpose.AnonymousIdentificationModule_Ticket)); }
public string ToEncryptedTicket() { if (!Roles.Enabled) { return(null); } if (_Identity != null && !_Identity.IsAuthenticated) { return(null); } if (_Identity == null && string.IsNullOrEmpty(_Username)) { return(null); } if (_Roles.Count > Roles.MaxCachedResults) { return(null); } MemoryStream ms = new System.IO.MemoryStream(); byte[] buf = null; IIdentity id = _Identity; try { _Identity = null; BinaryFormatter bf = new BinaryFormatter(); bool originalSerializingForCookieValue = _serializingForCookie; try { // DevDiv 481327: ClaimsPrincipal is an expensive type to serialize and deserialize. If the developer is using // role management, then he is going to be querying regular ASP.NET membership roles rather than claims, so // we can cut back on the number of bytes sent across the wire by ignoring any claims in the underlying // identity. Otherwise we risk sending a cookie too large for the browser to handle. _serializingForCookie = true; bf.Serialize(ms, this); } finally { _serializingForCookie = originalSerializingForCookieValue; } buf = ms.ToArray(); } finally { ms.Close(); _Identity = id; } return(CookieProtectionHelper.Encode(Roles.CookieProtectionValue, buf, Purpose.RolePrincipal_Ticket)); }
public string ToEncryptedTicket() { if (!Roles.Enabled) { return(null); } if ((this._Identity != null) && !this._Identity.IsAuthenticated) { return(null); } if ((this._Identity == null) && string.IsNullOrEmpty(this._Username)) { return(null); } if (this._Roles.Count > Roles.MaxCachedResults) { return(null); } MemoryStream serializationStream = new MemoryStream(); byte[] buf = null; IIdentity identity = this._Identity; try { this._Identity = null; new BinaryFormatter().Serialize(serializationStream, this); buf = serializationStream.ToArray(); } finally { serializationStream.Close(); this._Identity = identity; } return(CookieProtectionHelper.Encode(Roles.CookieProtectionValue, buf, buf.Length)); }