示例#1
0
        /// <summary>
        /// Creates a redirect.
        /// </summary>
        /// <param name="redirectMapping">The redirect mapping.</param>
        public void CreateRedirect(IRedirectMapping redirectMapping)
        {
            var stream = new MemoryStream();
            var tempStream = new MemoryStream();
            using (var streamWriter = new StreamWriter(tempStream))
            {
                switch (redirectMapping.RedirectType)
                {
                    case RedirectType.Permanent:
                        streamWriter.WriteLine("HTTP/1.1 301 Moved Permanently");
                        break;
                    case RedirectType.Temporary:
                        streamWriter.WriteLine("HTTP/1.1 302 Found");
                        break;
                    default:
                        throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture,
                                                                  "The redirect type '{0}' is not supported.", redirectMapping.RedirectType));
                }

                streamWriter.WriteLine("Location: " + redirectMapping.Uri.AbsoluteUri);
                streamWriter.Flush();

                tempStream.Seek(0, SeekOrigin.Begin);
                tempStream.WriteTo(stream);
            }

            stream.Seek(0, SeekOrigin.Begin);

            this.OnStreamAvailable(stream);
        }
示例#2
0
        /// <summary>
        /// Creates a redirect.
        /// </summary>
        /// <param name="redirectMapping">The redirect mapping.</param>
        public void CreateRedirect(IRedirectMapping redirectMapping)
        {
            var stream     = new MemoryStream();
            var tempStream = new MemoryStream();

            using (var streamWriter = new StreamWriter(tempStream))
            {
                switch (redirectMapping.RedirectType)
                {
                case RedirectType.Permanent:
                    streamWriter.WriteLine("HTTP/1.1 301 Moved Permanently");
                    break;

                case RedirectType.Temporary:
                    streamWriter.WriteLine("HTTP/1.1 302 Found");
                    break;

                default:
                    throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture,
                                                              "The redirect type '{0}' is not supported.", redirectMapping.RedirectType));
                }

                streamWriter.WriteLine("Location: " + redirectMapping.Uri.AbsoluteUri);
                streamWriter.Flush();

                tempStream.Seek(0, SeekOrigin.Begin);
                tempStream.WriteTo(stream);
            }

            stream.Seek(0, SeekOrigin.Begin);

            this.OnStreamAvailable(stream);
        }