Code:
/ FXUpdate3074 / FXUpdate3074 / 1.1 / untmp / whidbey / QFE / ndp / fx / src / xsp / System / Web / DataAccess / ADConnectionHelper.cs / 1 / ADConnectionHelper.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.DataAccess { using System.Net; using System.Diagnostics; using System.Web.Hosting; using System.Web.Security; using System.DirectoryServices; using System.DirectoryServices.Protocols; internal static class ActiveDirectoryConnectionHelper { internal static DirectoryEntryHolder GetDirectoryEntry(DirectoryInformation directoryInfo, string objectDN, bool revertImpersonation) { Debug.Assert ((objectDN != null) && (objectDN.Length != 0)); // // Get the adspath and create a directory entry holder // DirectoryEntryHolder holder = new DirectoryEntryHolder(new DirectoryEntry ( directoryInfo.GetADsPath(objectDN), directoryInfo.GetUsername(), directoryInfo.GetPassword(), directoryInfo.AuthenticationTypes)); // // If revertImpersonation is true, we need to revert // holder.Open(null, revertImpersonation); return holder; } } internal sealed class DirectoryEntryHolder { private ImpersonationContext ctx = null; private bool opened; private DirectoryEntry entry; internal DirectoryEntryHolder (DirectoryEntry entry) { Debug.Assert (entry != null); this.entry = entry; } internal void Open (HttpContext context, bool revertImpersonate) { if (opened) return; // Already opened // // Revert client impersonation if required // if (revertImpersonate) { ctx = new ApplicationImpersonationContext(); } else { ctx = null; } opened = true; // Open worked! } internal void Close () { if (!opened) // Not open! return; entry.Dispose(); RestoreImpersonation(); opened = false; } internal void RestoreImpersonation() { // Restore impersonation if (ctx != null) { ctx.Undo(); ctx = null; } } internal DirectoryEntry DirectoryEntry { get { return entry; } } } } // 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
- DPCustomTypeDescriptor.cs
- ControlUtil.cs
- Panel.cs
- MetadataItemSerializer.cs
- DesignerValidationSummaryAdapter.cs
- LookupBindingPropertiesAttribute.cs
- PipeSecurity.cs
- AnimationException.cs
- CompiledAction.cs
- TextRangeEditLists.cs
- Marshal.cs
- UpdatePanel.cs
- path.cs
- SHA1Managed.cs
- EdmRelationshipRoleAttribute.cs
- DPCustomTypeDescriptor.cs
- DayRenderEvent.cs
- NetworkInformationPermission.cs
- ProfileSettings.cs
- SamlEvidence.cs
- XmlSchemaInferenceException.cs
- GifBitmapDecoder.cs
- PasswordTextNavigator.cs
- CodeAttributeArgumentCollection.cs
- ListViewHitTestInfo.cs
- Perspective.cs
- __Filters.cs
- SamlAudienceRestrictionCondition.cs
- PassportAuthentication.cs
- TileBrush.cs
- TdsParserStateObject.cs
- HttpListener.cs
- ContextProperty.cs
- LockRecoveryTask.cs
- COM2Properties.cs
- DiagnosticsConfigurationHandler.cs
- SmiGettersStream.cs
- AnyAllSearchOperator.cs
- MemberNameValidator.cs
- XamlFxTrace.cs
- GridViewDeletedEventArgs.cs
- DataGridViewColumnEventArgs.cs
- UntypedNullExpression.cs
- QilPatternFactory.cs
- JoinSymbol.cs
- ExpressionPrinter.cs
- EDesignUtil.cs
- WindowsListBox.cs
- ScriptManagerProxy.cs
- EdgeModeValidation.cs
- AnonymousIdentificationSection.cs
- BitStack.cs
- SqlConnectionStringBuilder.cs
- CodePropertyReferenceExpression.cs
- AttachedPropertyBrowsableForTypeAttribute.cs
- CompilerTypeWithParams.cs
- ArgumentDesigner.xaml.cs
- UnsafeNativeMethods.cs
- DecoderFallbackWithFailureFlag.cs
- LinearQuaternionKeyFrame.cs
- SelectionHighlightInfo.cs
- KerberosSecurityTokenProvider.cs
- ProfileGroupSettingsCollection.cs
- SQLInt16.cs
- RegexMatch.cs
- DirectoryNotFoundException.cs
- ListBoxItemWrapperAutomationPeer.cs
- GestureRecognizer.cs
- EntityConnection.cs
- FigureHelper.cs
- TextDpi.cs
- CustomPopupPlacement.cs
- TcpHostedTransportConfiguration.cs
- SafeFileMapViewHandle.cs
- CombinedGeometry.cs
- HttpGetServerProtocol.cs
- ITreeGenerator.cs
- EnterpriseServicesHelper.cs
- Marshal.cs
- SiteMapDataSourceView.cs
- ReadOnlyHierarchicalDataSource.cs
- StylusPoint.cs
- DependencyPropertyDescriptor.cs
- IndexedGlyphRun.cs
- RepeatInfo.cs
- EditorPart.cs
- SafeProcessHandle.cs
- InternalMappingException.cs
- DesignerHelpers.cs
- ResourceDescriptionAttribute.cs
- ActivityStateQuery.cs
- DateBoldEvent.cs
- IndicFontClient.cs
- KeyedHashAlgorithm.cs
- ManagedIStream.cs
- Item.cs
- HtmlInputFile.cs
- TextLineResult.cs
- CodeNamespace.cs
- CodeDOMUtility.cs