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
- XmlAttributeAttribute.cs
- COAUTHINFO.cs
- TimersDescriptionAttribute.cs
- RectKeyFrameCollection.cs
- FontResourceCache.cs
- BlockUIContainer.cs
- IntegerFacetDescriptionElement.cs
- DataGridComponentEditor.cs
- ReflectionTypeLoadException.cs
- base64Transforms.cs
- KeyProperty.cs
- SelectorItemAutomationPeer.cs
- ProxyWebPartManager.cs
- InvalidMessageContractException.cs
- CompatibleComparer.cs
- ActionFrame.cs
- FilteredSchemaElementLookUpTable.cs
- ListViewInsertionMark.cs
- MappingException.cs
- RadialGradientBrush.cs
- SmiConnection.cs
- SystemPens.cs
- LongValidatorAttribute.cs
- SqlRemoveConstantOrderBy.cs
- BoolExpressionVisitors.cs
- IISMapPath.cs
- VisualProxy.cs
- QuaternionAnimation.cs
- NavigationFailedEventArgs.cs
- XPathNodeIterator.cs
- CapabilitiesUse.cs
- ProcessHostMapPath.cs
- DbConnectionPoolGroupProviderInfo.cs
- FontCacheLogic.cs
- ControlValuePropertyAttribute.cs
- ColumnCollection.cs
- WindowsGraphicsWrapper.cs
- BrowsableAttribute.cs
- Qualifier.cs
- DefaultPropertyAttribute.cs
- AxisAngleRotation3D.cs
- OdbcEnvironment.cs
- RuntimeIdentifierPropertyAttribute.cs
- TransformationRules.cs
- PersistenceTypeAttribute.cs
- ExceptionHandlersDesigner.cs
- GroupItemAutomationPeer.cs
- TagPrefixCollection.cs
- TreeNodeConverter.cs
- ComNativeDescriptor.cs
- DataGridViewColumnCollectionDialog.cs
- MouseGesture.cs
- WebPartAuthorizationEventArgs.cs
- HostExecutionContextManager.cs
- PointHitTestParameters.cs
- ResizeGrip.cs
- ProxyAttribute.cs
- SafeNativeMemoryHandle.cs
- XMLSchema.cs
- LayoutTableCell.cs
- AuditLevel.cs
- EventlogProvider.cs
- MetaModel.cs
- HttpApplicationFactory.cs
- ControlPropertyNameConverter.cs
- ShaderEffect.cs
- TdsParserHelperClasses.cs
- TextBoxRenderer.cs
- ArglessEventHandlerProxy.cs
- DesignerActionService.cs
- NewExpression.cs
- PolicyImporterElement.cs
- BindToObject.cs
- WindowsListBox.cs
- JsonReader.cs
- FixedSOMElement.cs
- ProxyWebPartManager.cs
- Timer.cs
- Message.cs
- Point.cs
- PieceNameHelper.cs
- Throw.cs
- ToolStripContainer.cs
- SqlCommand.cs
- SystemColors.cs
- TargetException.cs
- BamlResourceContent.cs
- TableRowCollection.cs
- FolderNameEditor.cs
- EarlyBoundInfo.cs
- AuthenticationModuleElement.cs
- PropertyDescriptor.cs
- DrawingImage.cs
- ToolStripDropTargetManager.cs
- Attributes.cs
- SerialPort.cs
- XmlAnyElementAttribute.cs
- ParallelRangeManager.cs
- ToolStripHighContrastRenderer.cs
- Help.cs