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
- ApplicationSecurityInfo.cs
- ContentTextAutomationPeer.cs
- EventLogLink.cs
- WebHttpBehavior.cs
- MailHeaderInfo.cs
- Stacktrace.cs
- Win32SafeHandles.cs
- GridViewAutomationPeer.cs
- JsonWriterDelegator.cs
- SiteMapDataSource.cs
- GeneratedCodeAttribute.cs
- DataTableCollection.cs
- AssemblyCache.cs
- SemanticResultValue.cs
- Underline.cs
- XsltContext.cs
- OneOfConst.cs
- BinaryObjectReader.cs
- ContentWrapperAttribute.cs
- LinkButton.cs
- TextLine.cs
- ToolStripArrowRenderEventArgs.cs
- QilStrConcatenator.cs
- XmlnsCache.cs
- SafeEventLogWriteHandle.cs
- ResumeStoryboard.cs
- Marshal.cs
- OutOfProcStateClientManager.cs
- WebHttpSecurityElement.cs
- ProfileSection.cs
- CompilationUtil.cs
- CoTaskMemHandle.cs
- SafeNativeMethods.cs
- ControlType.cs
- ProxyHelper.cs
- QueryOutputWriter.cs
- MatrixCamera.cs
- SchemaNotation.cs
- SafeProcessHandle.cs
- XmlSerializableWriter.cs
- FontStyle.cs
- LinqDataSourceDeleteEventArgs.cs
- ResourceReferenceExpression.cs
- SmtpClient.cs
- _BufferOffsetSize.cs
- BaseTemplateCodeDomTreeGenerator.cs
- CodeDomDesignerLoader.cs
- AsymmetricSignatureFormatter.cs
- OrderedHashRepartitionEnumerator.cs
- RawStylusInputCustomData.cs
- SessionEndedEventArgs.cs
- RemoteHelper.cs
- TextRangeEditLists.cs
- SystemResourceHost.cs
- remotingproxy.cs
- AsyncDataRequest.cs
- CompareInfo.cs
- ValidationPropertyAttribute.cs
- Trace.cs
- NotConverter.cs
- RepeatButtonAutomationPeer.cs
- ImageList.cs
- TextDpi.cs
- AlternateView.cs
- BinaryMessageEncoder.cs
- TimeSpanHelper.cs
- Calendar.cs
- OracleDataAdapter.cs
- ClientTargetSection.cs
- RegexInterpreter.cs
- DataColumnPropertyDescriptor.cs
- DataGridItemEventArgs.cs
- basecomparevalidator.cs
- RepeaterItem.cs
- FormatException.cs
- DeflateEmulationStream.cs
- SystemIPGlobalProperties.cs
- XXXInfos.cs
- IPHostEntry.cs
- XPathNavigator.cs
- HandlerMappingMemo.cs
- DataGridViewRowCancelEventArgs.cs
- GridViewCellAutomationPeer.cs
- UpdateManifestForBrowserApplication.cs
- XmlExpressionDumper.cs
- LocationUpdates.cs
- FixedSOMTableCell.cs
- NavigationWindowAutomationPeer.cs
- EditorZone.cs
- UshortList2.cs
- RMEnrollmentPage3.cs
- NegotiationTokenProvider.cs
- KeyToListMap.cs
- Vector3DValueSerializer.cs
- DispatcherExceptionFilterEventArgs.cs
- ZipIOExtraFieldElement.cs
- KeySpline.cs
- CLRBindingWorker.cs
- EntityCollectionChangedParams.cs
- Exception.cs