Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx35 / System.ServiceModel.Web / System / ServiceModel / Dispatcher / JavascriptCallbackMessageInspector.cs / 1305376 / JavascriptCallbackMessageInspector.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- #pragma warning disable 1634, 1691 namespace System.ServiceModel.Dispatcher { using System.Net; using System.Linq; using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.Web; using System.Web; using System.ServiceModel.Description; using System.Diagnostics; using System.ServiceModel.Diagnostics; class JavascriptCallbackMessageInspector : IDispatchMessageInspector { internal static readonly string applicationJavaScriptMediaType = "application/x-javascript"; public JavascriptCallbackMessageInspector(string callbackParameterName) { this.CallbackParameterName = callbackParameterName; if (DiagnosticUtility.ShouldTraceInformation) { TraceUtility.TraceEvent(TraceEventType.Information, TraceCode.JsonpCallbackNameSet, SR2.GetString(SR2.TraceCodeJsonpCallbackNameSet, callbackParameterName)); } } string CallbackParameterName { get; set; } public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext) { if (HttpContext.Current != null && HttpContext.Current.User != null && HttpContext.Current.User.Identity != null && HttpContext.Current.User.Identity.IsAuthenticated) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR2.CrossDomainJavascriptAuthNotSupported)); } return null; } public void BeforeSendReply(ref Message reply, object correlationState) { WebBodyFormatMessageProperty formatProperty; JavascriptCallbackResponseMessageProperty javascriptCallbackResponseMessageProperty = null; if (reply.Properties.TryGetValue(WebBodyFormatMessageProperty.Name, out formatProperty) && formatProperty != null && formatProperty.Format == WebContentFormat.Json) { if (!reply.Properties.TryGetValue (JavascriptCallbackResponseMessageProperty.Name, out javascriptCallbackResponseMessageProperty) || javascriptCallbackResponseMessageProperty == null) { javascriptCallbackResponseMessageProperty = WebHttpBehavior.TrySetupJavascriptCallback(this.CallbackParameterName); if (javascriptCallbackResponseMessageProperty != null) { reply.Properties.Add(JavascriptCallbackResponseMessageProperty.Name, javascriptCallbackResponseMessageProperty); } } if (javascriptCallbackResponseMessageProperty != null) { HttpResponseMessageProperty property; if (reply.Properties.TryGetValue (HttpResponseMessageProperty.Name, out property) && property != null) { property.Headers[HttpResponseHeader.ContentType] = applicationJavaScriptMediaType; if (javascriptCallbackResponseMessageProperty.StatusCode == null) { javascriptCallbackResponseMessageProperty.StatusCode = property.StatusCode; } property.StatusCode = HttpStatusCode.OK; if (property.SuppressEntityBody) { property.SuppressEntityBody = false; Message nullJsonMessage = WebOperationContext.Current.CreateJsonResponse
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SQLSingleStorage.cs
- AuthenticationModuleElementCollection.cs
- ListChunk.cs
- LogReserveAndAppendState.cs
- CodeAssignStatement.cs
- HtmlElementEventArgs.cs
- Selector.cs
- PackageRelationshipSelector.cs
- IntSecurity.cs
- Timer.cs
- DataKeyCollection.cs
- XslUrlEditor.cs
- PageThemeBuildProvider.cs
- SingleAnimation.cs
- ManifestSignatureInformation.cs
- HMACMD5.cs
- Helper.cs
- EndOfStreamException.cs
- CodeArrayCreateExpression.cs
- OutputCacheSettings.cs
- CorrelationManager.cs
- InputLanguageProfileNotifySink.cs
- EntitySqlQueryCacheKey.cs
- WebRequest.cs
- ReliableRequestSessionChannel.cs
- XmlNodeChangedEventArgs.cs
- XmlComment.cs
- WebException.cs
- Window.cs
- IIS7UserPrincipal.cs
- VirtualizedItemProviderWrapper.cs
- AppearanceEditorPart.cs
- DetailsViewUpdateEventArgs.cs
- TextEditorCharacters.cs
- AttributeQuery.cs
- BaseTypeViewSchema.cs
- keycontainerpermission.cs
- XmlArrayAttribute.cs
- FilterRepeater.cs
- HttpCacheParams.cs
- IntegerCollectionEditor.cs
- NotSupportedException.cs
- SingleAnimation.cs
- Queue.cs
- PageRanges.cs
- ProviderManager.cs
- MetadataPropertyAttribute.cs
- SettingsPropertyValue.cs
- ThicknessAnimationBase.cs
- Interlocked.cs
- UnsafeCollabNativeMethods.cs
- Tokenizer.cs
- SpeakCompletedEventArgs.cs
- SelectionChangedEventArgs.cs
- Image.cs
- CDSsyncETWBCLProvider.cs
- NamespaceQuery.cs
- QuaternionAnimation.cs
- ForEach.cs
- TableCellAutomationPeer.cs
- ObjectSet.cs
- ProtectedConfigurationSection.cs
- RandomDelaySendsAsyncResult.cs
- MediaPlayer.cs
- AttributeCollection.cs
- TreeNodeBinding.cs
- Privilege.cs
- SqlAggregateChecker.cs
- TextFormatter.cs
- SettingsAttributes.cs
- ZoneLinkButton.cs
- BackgroundWorker.cs
- Brush.cs
- ADConnectionHelper.cs
- RootBrowserWindowAutomationPeer.cs
- ZipIOLocalFileBlock.cs
- FileSystemInfo.cs
- BindingManagerDataErrorEventArgs.cs
- FragmentQueryKB.cs
- UpDownBase.cs
- TraceListener.cs
- SqlLiftWhereClauses.cs
- RowVisual.cs
- DNS.cs
- StatusStrip.cs
- UInt32Converter.cs
- CorrelationQueryBehavior.cs
- SqlCacheDependency.cs
- HttpApplication.cs
- AssemblyNameProxy.cs
- FontCacheUtil.cs
- WmlLinkAdapter.cs
- ScrollEvent.cs
- ConstraintCollection.cs
- RawStylusInputCustomDataList.cs
- SqlInfoMessageEvent.cs
- DuplicateWaitObjectException.cs
- CustomAttributeBuilder.cs
- ComponentEvent.cs
- LinkTarget.cs