/// <summary> /// Automatically sends the appropriate response to the user agent /// and ends execution on the current page or handler. /// </summary> /// <exception cref="ThreadAbortException">Thrown by ASP.NET in order to prevent additional data from the page being sent to the client and corrupting the response.</exception> /// <remarks> /// Requires a current HttpContext. /// </remarks> public virtual void Send() { ErrorUtilities.VerifyOperation(HttpContext.Current != null, MessagingStrings.CurrentHttpContextRequired); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.StatusCode = (int)this.Status; MessagingUtilities.ApplyHeadersToResponse(this.Headers, HttpContext.Current.Response); if (this.ResponseStream != null) { try { this.ResponseStream.CopyTo(HttpContext.Current.Response.OutputStream); } catch (HttpException ex) { if (ex.ErrorCode == -2147467259 && HttpContext.Current.Response.Output != null) { // Test scenarios can generate this, since the stream is being spoofed: // System.Web.HttpException: OutputStream is not available when a custom TextWriter is used. HttpContext.Current.Response.Output.Write(this.Body); } else { throw; } } } HttpContext.Current.Response.End(); }
/// <summary> /// Gets an offline snapshot version of this instance. /// </summary> /// <param name="maximumBytesToCache">The maximum bytes from the response stream to cache.</param> /// <returns>A snapshot version of this instance.</returns> /// <remarks> /// If this instance is a <see cref="NetworkDirectWebResponse"/> creating a snapshot /// will automatically close and dispose of the underlying response stream. /// If this instance is a <see cref="CachedDirectWebResponse"/>, the result will /// be the self same instance. /// </remarks> internal override CachedDirectWebResponse GetSnapshot(int maximumBytesToCache) { ErrorUtilities.VerifyOperation(!this.streamReadBegun, "Network stream reading has already begun."); this.streamReadBegun = true; var result = new CachedDirectWebResponse(this.RequestUri, this.httpWebResponse, maximumBytesToCache); this.Dispose(); return(result); }
internal static void VerifyHttpContext() { ErrorUtilities.VerifyOperation(HttpContext.Current != null && HttpContext.Current.Request != null, MessagingStrings.HttpContextRequired); }
internal static void VerifyHttpContext(HttpContext ctx) { ErrorUtilities.VerifyOperation(ctx != null && ctx.Request != null, MessagingStrings.HttpContextRequired); }