Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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. // //----------------------------------------------------------------------------- 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
- UIElementCollection.cs
- FileDataSourceCache.cs
- QuadraticBezierSegment.cs
- AudioFormatConverter.cs
- CompiledQuery.cs
- Win32Native.cs
- ResizingMessageFilter.cs
- DiscoveryDocumentSearchPattern.cs
- ModelUIElement3D.cs
- CellPartitioner.cs
- HTTPAPI_VERSION.cs
- SparseMemoryStream.cs
- SqlMethodCallConverter.cs
- graph.cs
- SubMenuStyle.cs
- _BufferOffsetSize.cs
- SortDescriptionCollection.cs
- Normalization.cs
- Pen.cs
- localization.cs
- Visitor.cs
- TextTrailingCharacterEllipsis.cs
- CacheMemory.cs
- CustomPopupPlacement.cs
- SymLanguageVendor.cs
- PageParserFilter.cs
- DocumentXPathNavigator.cs
- ComponentResourceManager.cs
- GetIndexBinder.cs
- RepeaterCommandEventArgs.cs
- NestedContainer.cs
- PriorityBindingExpression.cs
- SqlInfoMessageEvent.cs
- DataSourceBooleanViewSchemaConverter.cs
- Rfc2898DeriveBytes.cs
- Span.cs
- DrawingContextDrawingContextWalker.cs
- LinkClickEvent.cs
- WebServiceErrorEvent.cs
- _HeaderInfoTable.cs
- PropertyMapper.cs
- CertificateManager.cs
- XmlElementCollection.cs
- HtmlInputButton.cs
- ListControlDesigner.cs
- BamlVersionHeader.cs
- BaseValidatorDesigner.cs
- ButtonBaseAutomationPeer.cs
- Image.cs
- sqlpipe.cs
- NavigationPropertyEmitter.cs
- TypeContext.cs
- ComplusTypeValidator.cs
- LoadGrammarCompletedEventArgs.cs
- PrintingPermissionAttribute.cs
- Util.cs
- MergablePropertyAttribute.cs
- RectAnimationClockResource.cs
- FixedTextPointer.cs
- FileDialogCustomPlaces.cs
- documentsequencetextview.cs
- PointValueSerializer.cs
- SspiHelper.cs
- DependencySource.cs
- ObjectDataSourceMethodEventArgs.cs
- DateTimeUtil.cs
- DataControlField.cs
- MobileRedirect.cs
- ResourceProviderFactory.cs
- AutoResizedEvent.cs
- RuntimeArgumentHandle.cs
- CheckBox.cs
- HttpStreams.cs
- PerformanceCounterPermissionAttribute.cs
- Dictionary.cs
- LinkLabel.cs
- ValidatedControlConverter.cs
- DataBoundControlAdapter.cs
- TypeConverter.cs
- VarRemapper.cs
- ServiceDeploymentInfo.cs
- keycontainerpermission.cs
- DashStyles.cs
- HwndHost.cs
- SortDescription.cs
- CharacterHit.cs
- ExceptionUtil.cs
- SessionState.cs
- CancelRequestedQuery.cs
- ExtentCqlBlock.cs
- FrameworkObject.cs
- TransactionException.cs
- TimeEnumHelper.cs
- GridViewPageEventArgs.cs
- Bold.cs
- PocoEntityKeyStrategy.cs
- HtmlTableRow.cs
- DbSetClause.cs
- GridViewCommandEventArgs.cs
- SynchronizationContext.cs