Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / NetFx35 / System.ServiceModel.Web / System / ServiceModel / Dispatcher / WebErrorHandler.cs / 1 / WebErrorHandler.cs
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------
#pragma warning disable 1634, 1691
namespace System.ServiceModel.Dispatcher
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.ServiceModel;
using System.Text;
using System.Xml;
using System.Net;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Web;
using System.IO;
class WebErrorHandler : IErrorHandler
{
bool includeExceptionDetailInFaults;
public WebErrorHandler(bool includeExceptionDetailInFaults)
{
this.includeExceptionDetailInFaults = includeExceptionDetailInFaults;
}
public bool HandleError(Exception error)
{
return false;
}
public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
{
if (version != MessageVersion.None || error == null)
{
return;
}
MemoryStream stream = new MemoryStream();
WriteErrorPage(stream, error);
stream.Seek(0, SeekOrigin.Begin);
fault = new HttpStreamMessage(stream);
fault.Properties.Add(WebBodyFormatMessageProperty.Name, WebBodyFormatMessageProperty.RawProperty);
HttpResponseMessageProperty responseProperty = new HttpResponseMessageProperty();
responseProperty.StatusCode = HttpStatusCode.BadRequest;
responseProperty.Headers[HttpResponseHeader.ContentType] = "text/html";
fault.Properties.Add(HttpResponseMessageProperty.Name, responseProperty);
}
public void WriteErrorPage(Stream stream, Exception error)
{
string errorText;
string stackTrace;
if (this.includeExceptionDetailInFaults)
{
errorText = SR2.GetString(SR2.ServerErrorProcessingRequestWithDetails, error.Message);
stackTrace = error.StackTrace;
}
else
{
errorText = SR2.GetString(SR2.ServerErrorProcessingRequest);
stackTrace = null;
}
using (XmlWriter writer = XmlWriter.Create(stream))
{
writer.WriteStartElement("HTML");
writer.WriteStartElement("HEAD");
writer.WriteRaw(String.Format(CultureInfo.InvariantCulture,
@"{0}
{1} ",
SR2.GetString(SR2.HelpPageLayout),
SR2.GetString(SR2.WebErrorPageTitleText)));
writer.WriteEndElement(); //HEAD
writer.WriteRaw(String.Format(CultureInfo.InvariantCulture,
@"
{0}
{1}
{2}
",
SR2.GetString(SR2.WebErrorPageTitleText),
errorText,
stackTrace ?? string.Empty));
writer.WriteEndElement(); //HTML
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- GridViewRowCollection.cs
- COAUTHINFO.cs
- ThreadExceptionDialog.cs
- PageThemeCodeDomTreeGenerator.cs
- IdnElement.cs
- _AutoWebProxyScriptHelper.cs
- CodeLinePragma.cs
- TableAutomationPeer.cs
- WebPartConnectionsEventArgs.cs
- ToolStripPanelRow.cs
- Header.cs
- ObjectKeyFrameCollection.cs
- ConfigDefinitionUpdates.cs
- HasCopySemanticsAttribute.cs
- DefaultPropertiesToSend.cs
- Rotation3D.cs
- PrtTicket_Base.cs
- Region.cs
- SplitterCancelEvent.cs
- CharUnicodeInfo.cs
- HtmlElementCollection.cs
- ProtocolException.cs
- SecuritySessionFilter.cs
- DbParameterHelper.cs
- HttpDictionary.cs
- IdentifierCreationService.cs
- DictionaryManager.cs
- ValidationResult.cs
- Set.cs
- PathSegment.cs
- ItemCollection.cs
- CacheDependency.cs
- TextParagraphProperties.cs
- DataGridViewCellStyleBuilderDialog.cs
- CompilerGlobalScopeAttribute.cs
- ViewStateException.cs
- ToolStripSystemRenderer.cs
- WebPartCatalogCloseVerb.cs
- PreloadedPackages.cs
- HtmlEncodedRawTextWriter.cs
- SqlVisitor.cs
- ZipIORawDataFileBlock.cs
- TypeSystemHelpers.cs
- BamlBinaryReader.cs
- ProfileEventArgs.cs
- NumericUpDownAcceleration.cs
- TextEditorTables.cs
- IsolatedStorageFileStream.cs
- FileEnumerator.cs
- QueryAccessibilityHelpEvent.cs
- ApplicationDirectoryMembershipCondition.cs
- XmlRawWriterWrapper.cs
- _NativeSSPI.cs
- NativeMethodsOther.cs
- DoubleUtil.cs
- TreeNodeClickEventArgs.cs
- DbReferenceCollection.cs
- AtomEntry.cs
- SoapClientProtocol.cs
- RemotingConfiguration.cs
- HttpListenerTimeoutManager.cs
- BuildProviderUtils.cs
- ExpressionVisitorHelpers.cs
- control.ime.cs
- Pair.cs
- CommonRemoteMemoryBlock.cs
- Pts.cs
- HttpListenerResponse.cs
- AttachInfo.cs
- COM2IVsPerPropertyBrowsingHandler.cs
- KeyProperty.cs
- PointKeyFrameCollection.cs
- LayoutTableCell.cs
- Control.cs
- EdmType.cs
- ExpressionCopier.cs
- XmlException.cs
- BoundPropertyEntry.cs
- Panel.cs
- MDIClient.cs
- Style.cs
- EncryptedType.cs
- DefaultHttpHandler.cs
- EditBehavior.cs
- COM2ComponentEditor.cs
- ToolStripSeparatorRenderEventArgs.cs
- OleDbPropertySetGuid.cs
- DataGridViewComboBoxColumn.cs
- IPAddress.cs
- CacheHelper.cs
- Emitter.cs
- MethodExpr.cs
- DataGridAddNewRow.cs
- RadioButton.cs
- ToolStripLabel.cs
- HandleDictionary.cs
- TimeSpan.cs
- FormsAuthenticationModule.cs
- FunctionDescription.cs
- GenericIdentity.cs