Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Web / DataAccess / ADConnectionHelper.cs / 1305376 / 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. // //----------------------------------------------------------------------------- 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SqlNotificationRequest.cs
- ComEventsHelper.cs
- InputReferenceExpression.cs
- xmlformatgeneratorstatics.cs
- SettingsBindableAttribute.cs
- path.cs
- CodeTypeConstructor.cs
- NavigatorInput.cs
- NumberFunctions.cs
- TabPanel.cs
- ServicePointManager.cs
- PersistenceException.cs
- StringValidatorAttribute.cs
- HttpModuleCollection.cs
- InlineCollection.cs
- DrawingAttributeSerializer.cs
- TrackingDataItemValue.cs
- ContextQuery.cs
- RelatedImageListAttribute.cs
- RelationshipManager.cs
- IntSecurity.cs
- ConnectionStringSettings.cs
- XmlSchemaSimpleContentRestriction.cs
- SqlProcedureAttribute.cs
- SchemaMerger.cs
- RepeaterDesigner.cs
- ThicknessAnimation.cs
- FormsAuthentication.cs
- TypeAccessException.cs
- PermissionToken.cs
- CodePageEncoding.cs
- BrowserDefinitionCollection.cs
- TextDecoration.cs
- Win32Exception.cs
- DynamicValidatorEventArgs.cs
- TdsEnums.cs
- FileUtil.cs
- CodeIndexerExpression.cs
- BuildManager.cs
- InputProviderSite.cs
- VectorCollectionConverter.cs
- WebPartVerbCollection.cs
- CryptoConfig.cs
- GPPOINT.cs
- RowUpdatedEventArgs.cs
- MethodInfo.cs
- Win32.cs
- SystemFonts.cs
- EncryptedHeader.cs
- InitializerFacet.cs
- SqlConnection.cs
- Timer.cs
- NameValueSectionHandler.cs
- XPathMessageFilter.cs
- FontFaceLayoutInfo.cs
- DefaultMemberAttribute.cs
- XamlPathDataSerializer.cs
- CompressedStack.cs
- ReadWriteObjectLock.cs
- ValidatedControlConverter.cs
- BitmapFrame.cs
- DesignerActionUIService.cs
- DocumentAutomationPeer.cs
- Setter.cs
- ObjectToIdCache.cs
- XslUrlEditor.cs
- SpellerInterop.cs
- SafeNativeMethodsCLR.cs
- ExtractedStateEntry.cs
- HierarchicalDataSourceConverter.cs
- OperationContext.cs
- HtmlInputCheckBox.cs
- CollectionBuilder.cs
- AspNetHostingPermission.cs
- NumericUpDownAccelerationCollection.cs
- SplineKeyFrames.cs
- CollectionChangedEventManager.cs
- ToolStripDropDownButton.cs
- VisualProxy.cs
- CommandField.cs
- Knowncolors.cs
- DrawListViewColumnHeaderEventArgs.cs
- SystemIPInterfaceProperties.cs
- DataGridView.cs
- BitmapEffectCollection.cs
- DocumentPage.cs
- SymbolResolver.cs
- CqlParser.cs
- SystemIcmpV6Statistics.cs
- MemoryMappedFileSecurity.cs
- JournalEntryStack.cs
- ListBoxChrome.cs
- DataRow.cs
- DataGridViewRowDividerDoubleClickEventArgs.cs
- SmtpDigestAuthenticationModule.cs
- SynchronizationLockException.cs
- StylusPointPropertyInfoDefaults.cs
- MsdtcClusterUtils.cs
- TimeEnumHelper.cs
- DataGridItemCollection.cs