Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / 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; } } } }
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ComponentDispatcherThread.cs
- OperationParameterInfoCollection.cs
- FileResponseElement.cs
- ValidationErrorCollection.cs
- IisTraceListener.cs
- AsyncResult.cs
- IdentityHolder.cs
- EmbeddedMailObjectsCollection.cs
- IpcServerChannel.cs
- SqlTriggerAttribute.cs
- HebrewCalendar.cs
- StaticResourceExtension.cs
- AsyncStreamReader.cs
- ipaddressinformationcollection.cs
- OletxDependentTransaction.cs
- HierarchicalDataBoundControlAdapter.cs
- DataTableCollection.cs
- AccessText.cs
- TimelineCollection.cs
- TextRangeAdaptor.cs
- ZipIOExtraFieldZip64Element.cs
- SqlInternalConnectionSmi.cs
- PolicyChain.cs
- ExpressionsCollectionConverter.cs
- ContainerParagraph.cs
- VBCodeProvider.cs
- TextSearch.cs
- ClientTargetSection.cs
- RuntimeConfigurationRecord.cs
- UrlAuthorizationModule.cs
- XmlSubtreeReader.cs
- ReadOnlyHierarchicalDataSource.cs
- PrimitiveXmlSerializers.cs
- PageCanvasSize.cs
- ClassDataContract.cs
- TimelineClockCollection.cs
- WebServiceErrorEvent.cs
- LineServicesCallbacks.cs
- RouteValueExpressionBuilder.cs
- BamlRecordReader.cs
- DetailsViewModeEventArgs.cs
- _PooledStream.cs
- Object.cs
- OleDbTransaction.cs
- ProfileEventArgs.cs
- InstanceContextManager.cs
- FileNameEditor.cs
- StaticSiteMapProvider.cs
- Thumb.cs
- PreviewPrintController.cs
- ObjectResult.cs
- BoundConstants.cs
- FlowDocumentPage.cs
- MimeFormReflector.cs
- DataServiceBuildProvider.cs
- DetailsViewRow.cs
- ContentIterators.cs
- TranslateTransform3D.cs
- IdentityReference.cs
- EditCommandColumn.cs
- ChangeBlockUndoRecord.cs
- DependencyStoreSurrogate.cs
- InfoCardRSACryptoProvider.cs
- WindowsMenu.cs
- DataColumn.cs
- TemplateModeChangedEventArgs.cs
- PeerCollaboration.cs
- BoundField.cs
- InvokeHandlers.cs
- FontFamily.cs
- ToolStripOverflowButton.cs
- securitymgrsite.cs
- CodeTypeDeclarationCollection.cs
- ZipIOLocalFileHeader.cs
- PackWebResponse.cs
- DrawingDrawingContext.cs
- InputProviderSite.cs
- QilParameter.cs
- ThousandthOfEmRealPoints.cs
- NativeCompoundFileAPIs.cs
- TransformerConfigurationWizardBase.cs
- SelectionPattern.cs
- PersonalizationDictionary.cs
- DesignerAttribute.cs
- Parser.cs
- SqlTrackingService.cs
- DataGridViewCellValidatingEventArgs.cs
- TreeWalkHelper.cs
- GenericTransactionFlowAttribute.cs
- SystemTcpConnection.cs
- CollectionViewGroup.cs
- PrivilegedConfigurationManager.cs
- MediaEntryAttribute.cs
- FilteredReadOnlyMetadataCollection.cs
- KeyValueConfigurationCollection.cs
- XmlAtomicValue.cs
- CommandID.cs
- XmlSchemaAnnotated.cs
- ManagementScope.cs
- CodeBlockBuilder.cs