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, @"", 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.{0}
{1}
{2}
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- FrameworkContentElement.cs
- TransformerInfo.cs
- InlineUIContainer.cs
- PerfCounterSection.cs
- EntityDataSourceColumn.cs
- DataServiceRequest.cs
- BitmapEffectGeneralTransform.cs
- EmptyReadOnlyDictionaryInternal.cs
- AuthenticationService.cs
- HttpListenerElement.cs
- counter.cs
- ToolStripOverflow.cs
- ImageClickEventArgs.cs
- ConnectionPoolManager.cs
- DrawingImage.cs
- EmptyControlCollection.cs
- SqlCharStream.cs
- EventHandlers.cs
- DesignerView.Commands.cs
- CommandPlan.cs
- SqlMetaData.cs
- AlternationConverter.cs
- ZeroOpNode.cs
- UnsafeNativeMethods.cs
- ClientConvert.cs
- EntityConnectionStringBuilder.cs
- BooleanFacetDescriptionElement.cs
- HorizontalAlignConverter.cs
- Win32Exception.cs
- ImageResources.Designer.cs
- ListView.cs
- XsltConvert.cs
- AdornerDecorator.cs
- odbcmetadatacolumnnames.cs
- SerializableAttribute.cs
- BinaryWriter.cs
- PixelFormat.cs
- InlinedLocationReference.cs
- ObjectConverter.cs
- Hash.cs
- ManagedWndProcTracker.cs
- XPathAncestorQuery.cs
- ClientSettingsProvider.cs
- FormViewModeEventArgs.cs
- ProxyFragment.cs
- WebPartTransformerAttribute.cs
- PolyQuadraticBezierSegment.cs
- sqlser.cs
- ADMembershipUser.cs
- DebugControllerThread.cs
- DivideByZeroException.cs
- UrlPropertyAttribute.cs
- XmlChildNodes.cs
- SpotLight.cs
- DataGridCaption.cs
- DataGridViewRowHeightInfoNeededEventArgs.cs
- AssemblyAttributesGoHere.cs
- _ConnectionGroup.cs
- PkcsMisc.cs
- Cursor.cs
- xmlNames.cs
- MaterialCollection.cs
- XmlSchemaInferenceException.cs
- AnimatedTypeHelpers.cs
- AttributeConverter.cs
- ListViewItemSelectionChangedEvent.cs
- RulePatternOps.cs
- HtmlForm.cs
- DataGridViewDataConnection.cs
- DesignerGenericWebPart.cs
- ErrorLog.cs
- RSAPKCS1SignatureFormatter.cs
- SqlStream.cs
- TextLineResult.cs
- SynthesizerStateChangedEventArgs.cs
- ListViewUpdatedEventArgs.cs
- Scene3D.cs
- XPathDocumentIterator.cs
- AlignmentYValidation.cs
- InvalidOleVariantTypeException.cs
- ObjectItemCachedAssemblyLoader.cs
- WhitespaceRule.cs
- ToolBarPanel.cs
- CubicEase.cs
- PeerNameRecord.cs
- MissingMethodException.cs
- VersionUtil.cs
- SelectionPattern.cs
- VarRefManager.cs
- SecurityPolicySection.cs
- RubberbandSelector.cs
- CrossAppDomainChannel.cs
- DataSvcMapFileSerializer.cs
- SharedUtils.cs
- Stack.cs
- RawStylusInputCustomData.cs
- SamlAction.cs
- SQLBinaryStorage.cs
- TrackPoint.cs
- SafeUserTokenHandle.cs