Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / System.ServiceModel.Activation / System / ServiceModel / Activation / HostingMessageProperty.cs / 1305376 / HostingMessageProperty.cs
//---------------------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------------------- namespace System.ServiceModel.Activation { using System.Runtime; using System.Security; using System.ServiceModel; sealed class HostingMessageProperty : IAspNetMessageProperty { const string name = "webhost"; [Fx.Tag.SecurityNote(Critical = "Keeps track of impersonated user, caller must use with care and call Dispose at the appropriate time.")] [SecurityCritical] HostedImpersonationContext impersonationContext; [Fx.Tag.SecurityNote(Critical = "Stores a SecurityCritical helper class that controls HttpContext.Current with an elevation." + "Need to ensure that HostedThreadData is constructed and used properly.")] [SecurityCritical] HostedThreadData currentThreadData; [Fx.Tag.SecurityNote(Critical = "Sets impersonation context from an arbitrary source, caller must guard.")] [SecurityCritical] internal HostingMessageProperty(HostedHttpRequestAsyncResult result) { Fx.Assert(ServiceHostingEnvironment.IsHosted, "should only be called in the hosted path"); if (ServiceHostingEnvironment.AspNetCompatibilityEnabled) { if (result.ImpersonationContext != null && result.ImpersonationContext.IsImpersonated) { this.impersonationContext = result.ImpersonationContext; this.impersonationContext.AddRef(); } currentThreadData = result.HostedThreadData; } this.OriginalRequestUri = result.OriginalRequestUri; } public Uri OriginalRequestUri { get; private set; } static internal string Name { get { return name; } } HostedImpersonationContext ImpersonationContext { [Fx.Tag.SecurityNote(Critical = "Keeps track of impersonated user, caller must use with care.", Safe = "Safe for Get, individual members of HostedImpersonationContext are protected.")] [SecuritySafeCritical] get { return impersonationContext; } } [Fx.Tag.SecurityNote(Critical = "Delegates to a SecurityCritical method in HostedThreadData." + "Caller must ensure that function is called appropriately and result is guarded and Dispose()'d correctly.")] [SecurityCritical] public IDisposable ApplyIntegrationContext() { if (ServiceHostingEnvironment.AspNetCompatibilityEnabled) { return currentThreadData.CreateContext(); } return null; } [Fx.Tag.SecurityNote(Critical = "Accesses SecurityCritical method HostedImpersonationContext.Impersonate." + "Caller should use with care, must take responsibility for reverting impersonation.")] [SecurityCritical] public IDisposable Impersonate() { if (this.ImpersonationContext != null) { return this.ImpersonationContext.Impersonate(); } else { return null; } } [Fx.Tag.SecurityNote(Critical = "Cleans up impersonationContext, which is critical.", Safe = "Doesn't leak anything.")] [SecuritySafeCritical] public void Close() { if (impersonationContext != null) { impersonationContext.Release(); impersonationContext = null; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------------------- namespace System.ServiceModel.Activation { using System.Runtime; using System.Security; using System.ServiceModel; sealed class HostingMessageProperty : IAspNetMessageProperty { const string name = "webhost"; [Fx.Tag.SecurityNote(Critical = "Keeps track of impersonated user, caller must use with care and call Dispose at the appropriate time.")] [SecurityCritical] HostedImpersonationContext impersonationContext; [Fx.Tag.SecurityNote(Critical = "Stores a SecurityCritical helper class that controls HttpContext.Current with an elevation." + "Need to ensure that HostedThreadData is constructed and used properly.")] [SecurityCritical] HostedThreadData currentThreadData; [Fx.Tag.SecurityNote(Critical = "Sets impersonation context from an arbitrary source, caller must guard.")] [SecurityCritical] internal HostingMessageProperty(HostedHttpRequestAsyncResult result) { Fx.Assert(ServiceHostingEnvironment.IsHosted, "should only be called in the hosted path"); if (ServiceHostingEnvironment.AspNetCompatibilityEnabled) { if (result.ImpersonationContext != null && result.ImpersonationContext.IsImpersonated) { this.impersonationContext = result.ImpersonationContext; this.impersonationContext.AddRef(); } currentThreadData = result.HostedThreadData; } this.OriginalRequestUri = result.OriginalRequestUri; } public Uri OriginalRequestUri { get; private set; } static internal string Name { get { return name; } } HostedImpersonationContext ImpersonationContext { [Fx.Tag.SecurityNote(Critical = "Keeps track of impersonated user, caller must use with care.", Safe = "Safe for Get, individual members of HostedImpersonationContext are protected.")] [SecuritySafeCritical] get { return impersonationContext; } } [Fx.Tag.SecurityNote(Critical = "Delegates to a SecurityCritical method in HostedThreadData." + "Caller must ensure that function is called appropriately and result is guarded and Dispose()'d correctly.")] [SecurityCritical] public IDisposable ApplyIntegrationContext() { if (ServiceHostingEnvironment.AspNetCompatibilityEnabled) { return currentThreadData.CreateContext(); } return null; } [Fx.Tag.SecurityNote(Critical = "Accesses SecurityCritical method HostedImpersonationContext.Impersonate." + "Caller should use with care, must take responsibility for reverting impersonation.")] [SecurityCritical] public IDisposable Impersonate() { if (this.ImpersonationContext != null) { return this.ImpersonationContext.Impersonate(); } else { return null; } } [Fx.Tag.SecurityNote(Critical = "Cleans up impersonationContext, which is critical.", Safe = "Doesn't leak anything.")] [SecuritySafeCritical] public void Close() { if (impersonationContext != null) { impersonationContext.Release(); impersonationContext = null; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ILGenerator.cs
- Internal.cs
- SecurityPermission.cs
- XComponentModel.cs
- PathFigureCollection.cs
- CodeVariableReferenceExpression.cs
- BufferAllocator.cs
- RootBrowserWindow.cs
- SchemaNotation.cs
- XmlNodeChangedEventArgs.cs
- DataGridViewRowCancelEventArgs.cs
- Listbox.cs
- TableItemPattern.cs
- XmlSchemaExporter.cs
- CacheVirtualItemsEvent.cs
- SharedConnectionInfo.cs
- ConfigurationPropertyCollection.cs
- TaiwanLunisolarCalendar.cs
- SelectionWordBreaker.cs
- keycontainerpermission.cs
- IPCCacheManager.cs
- AnimatedTypeHelpers.cs
- RegistryHandle.cs
- EnumerableWrapperWeakToStrong.cs
- TextParentUndoUnit.cs
- GridViewDeletedEventArgs.cs
- PropertySourceInfo.cs
- RSACryptoServiceProvider.cs
- ISFTagAndGuidCache.cs
- ButtonField.cs
- LocalizedNameDescriptionPair.cs
- _ListenerResponseStream.cs
- OLEDB_Util.cs
- ThemeDirectoryCompiler.cs
- XPathAncestorQuery.cs
- DrawListViewSubItemEventArgs.cs
- ReflectionServiceProvider.cs
- GridEntry.cs
- SubqueryTrackingVisitor.cs
- ReadOnlyTernaryTree.cs
- CombinedGeometry.cs
- SoapObjectReader.cs
- PointLight.cs
- datacache.cs
- InputScopeNameConverter.cs
- SerialErrors.cs
- SingleResultAttribute.cs
- ConsumerConnectionPoint.cs
- PeerContact.cs
- MsiStyleLogWriter.cs
- CategoryValueConverter.cs
- Assert.cs
- HTMLTagNameToTypeMapper.cs
- Ray3DHitTestResult.cs
- Int64Animation.cs
- TextPattern.cs
- ILGenerator.cs
- KeysConverter.cs
- LocalBuilder.cs
- SoapCodeExporter.cs
- SpellerInterop.cs
- SafeArrayRankMismatchException.cs
- VerificationAttribute.cs
- XmlLinkedNode.cs
- linebase.cs
- BackEase.cs
- exports.cs
- _UncName.cs
- EntitySet.cs
- RawStylusInputCustomData.cs
- Geometry3D.cs
- DotExpr.cs
- SessionViewState.cs
- _AutoWebProxyScriptWrapper.cs
- DesignerWidgets.cs
- ProtectedProviderSettings.cs
- TreeSet.cs
- HelpKeywordAttribute.cs
- Matrix3DConverter.cs
- CodeAssignStatement.cs
- GridViewRowEventArgs.cs
- NameSpaceExtractor.cs
- BindingExpressionBase.cs
- SerializationSectionGroup.cs
- Message.cs
- WorkflowMarkupElementEventArgs.cs
- OpacityConverter.cs
- DataGridTextBox.cs
- SourceItem.cs
- ImageSourceConverter.cs
- FloaterParaClient.cs
- QueryExecutionOption.cs
- ReachDocumentReferenceCollectionSerializer.cs
- GlobalProxySelection.cs
- HttpListener.cs
- PropertyDescriptor.cs
- TraceHandler.cs
- PackageStore.cs
- PresentationSource.cs
- Matrix3D.cs