public static string EncodeContextAsHttpSetCookieHeader(ContextMessageProperty context, Uri uri)
            {
                if (uri == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("uri");
                }
                if (context == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
                }

                MemoryStream stream = new MemoryStream();
                XmlWriterSettings writerSettings = new XmlWriterSettings();
                writerSettings.OmitXmlDeclaration = true;
                XmlWriter writer = XmlWriter.Create(stream, writerSettings);
                ContextMessageHeader contextHeader = new ContextMessageHeader(context.Context);
                contextHeader.WriteHeader(writer, MessageVersion.Default);
                writer.Flush();

                string result = string.Format(
                    CultureInfo.InvariantCulture,
                    "{0}=\"{1}\";Path={2}",
                    HttpCookieToolbox.ContextHttpCookieName,
                    Convert.ToBase64String(stream.GetBuffer(), 0, (int)stream.Length),
                    uri.AbsolutePath);

                return result;
            }
Example #2
0
            public static string EncodeContextAsHttpSetCookieHeader(ContextMessageProperty context, Uri uri)
            {
                if (uri == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("uri");
                }
                if (context == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
                }

                MemoryStream      stream         = new MemoryStream();
                XmlWriterSettings writerSettings = new XmlWriterSettings();

                writerSettings.OmitXmlDeclaration = true;
                XmlWriter            writer        = XmlWriter.Create(stream, writerSettings);
                ContextMessageHeader contextHeader = new ContextMessageHeader(context.Context);

                contextHeader.WriteHeader(writer, MessageVersion.Default);
                writer.Flush();

                string result = string.Format(
                    CultureInfo.InvariantCulture,
                    "{0}=\"{1}\";Path={2}",
                    HttpCookieToolbox.ContextHttpCookieName,
                    Convert.ToBase64String(stream.GetBuffer(), 0, (int)stream.Length),
                    uri.AbsolutePath);

                return(result);
            }