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
- TraceLevelStore.cs
- Point4D.cs
- ITextView.cs
- DBConnectionString.cs
- TreeNodeConverter.cs
- ModelVisual3D.cs
- PartialArray.cs
- HtmlHistory.cs
- RemoveStoryboard.cs
- ArgumentsParser.cs
- DataGridColumnReorderingEventArgs.cs
- TerminatorSinks.cs
- TreeNodeCollection.cs
- Utilities.cs
- SystemColors.cs
- InlineObject.cs
- BindingMemberInfo.cs
- CalendarDay.cs
- MenuItemBinding.cs
- XhtmlMobileTextWriter.cs
- SpeechDetectedEventArgs.cs
- ShaperBuffers.cs
- ConfigurationPropertyCollection.cs
- ColumnHeaderCollectionEditor.cs
- GlyphInfoList.cs
- Vector3D.cs
- AspCompat.cs
- DesignTimeParseData.cs
- URL.cs
- PixelFormatConverter.cs
- ManipulationCompletedEventArgs.cs
- JournalEntryStack.cs
- QilName.cs
- MenuAdapter.cs
- TimeSpanValidatorAttribute.cs
- SemaphoreFullException.cs
- TableParaClient.cs
- StringComparer.cs
- AutoResetEvent.cs
- SystemEvents.cs
- StyleBamlRecordReader.cs
- InheritanceContextHelper.cs
- WebPartDeleteVerb.cs
- XmlSecureResolver.cs
- PixelShader.cs
- SymmetricSecurityBindingElement.cs
- TableCellAutomationPeer.cs
- CodeIterationStatement.cs
- SuppressMessageAttribute.cs
- ValueTable.cs
- ValueSerializer.cs
- RemotingException.cs
- NavigateUrlConverter.cs
- ContentTypeSettingDispatchMessageFormatter.cs
- AppSecurityManager.cs
- Viewport2DVisual3D.cs
- SqlDataSourceCache.cs
- DocumentXPathNavigator.cs
- COMException.cs
- SQLDateTimeStorage.cs
- TreeNodeEventArgs.cs
- DispatcherSynchronizationContext.cs
- Camera.cs
- PeerTransportListenAddressValidatorAttribute.cs
- CdpEqualityComparer.cs
- KeyInstance.cs
- SafeNativeMethods.cs
- XmlDataCollection.cs
- DataViewSetting.cs
- XmlArrayItemAttribute.cs
- COM2Enum.cs
- SizeF.cs
- HierarchicalDataBoundControl.cs
- GridSplitter.cs
- RequestNavigateEventArgs.cs
- ValueQuery.cs
- SystemUdpStatistics.cs
- ReaderWriterLock.cs
- MaterializeFromAtom.cs
- ChildTable.cs
- TextServicesCompartmentContext.cs
- BridgeDataRecord.cs
- BinHexEncoder.cs
- XPathDocumentIterator.cs
- DataControlField.cs
- ApplicationServiceHelper.cs
- DocobjHost.cs
- SortQuery.cs
- Point3DIndependentAnimationStorage.cs
- EventsTab.cs
- XmlSchemaSimpleTypeList.cs
- ConcurrentStack.cs
- AdapterDictionary.cs
- EmptyQuery.cs
- SystemSounds.cs
- ObjectKeyFrameCollection.cs
- CallTemplateAction.cs
- XmlSubtreeReader.cs
- TypeNameConverter.cs
- X509PeerCertificateAuthenticationElement.cs