Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Net / System / Net / _WinHttpWebProxyDataBuilder.cs / 1305376 / _WinHttpWebProxyDataBuilder.cs
using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; namespace System.Net { internal sealed class WinHttpWebProxyBuilder : WebProxyDataBuilder { protected override void BuildInternal() { GlobalLog.Enter("WinHttpWebProxyBuilder#" + ValidationHelper.HashString(this) + "::BuildInternal()"); UnsafeNclNativeMethods.WinHttp.WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ieProxyConfig = new UnsafeNclNativeMethods.WinHttp.WINHTTP_CURRENT_USER_IE_PROXY_CONFIG(); // Make sure the native strings get freed, even if some unexpected exception occurs. RuntimeHelpers.PrepareConstrainedRegions(); try { if (UnsafeNclNativeMethods.WinHttp.WinHttpGetIEProxyConfigForCurrentUser(ref ieProxyConfig)) { string proxy = null; string proxyByPass = null; string autoConfigUrl = null; proxy = Marshal.PtrToStringUni(ieProxyConfig.Proxy); proxyByPass = Marshal.PtrToStringUni(ieProxyConfig.ProxyBypass); autoConfigUrl = Marshal.PtrToStringUni(ieProxyConfig.AutoConfigUrl); // note that ieProxyConfig.Proxy will be null if "use a proxy server" flag is turned off, even if // the user specified a proxy address. When we read directly from the Registry we need to check // for ProxyTypeFlags.PROXY_TYPE_PROXY. WinHttp does this for us and if the flag is not set, // ieProxyConfig.Proxy will be null. SetProxyAndBypassList(proxy, proxyByPass); SetAutoDetectSettings(ieProxyConfig.AutoDetect); // similar to comment above: ieProxyConfig.AutoConfigUrl will only be set if "automatically detect // settings" flag is set. We don't need to check ProxyTypeFlags.PROXY_TYPE_AUTO_PROXY_URL; WinHttp // takes care of it and sets AutoConfigUrl to null if the flag is not set, regardless of the actual // config script string. SetAutoProxyUrl(autoConfigUrl); } else { int errorCode = Marshal.GetLastWin32Error(); if (errorCode == Microsoft.Win32.NativeMethods.ERROR_NOT_ENOUGH_MEMORY) { throw new OutOfMemoryException(); } // if API call fails, rely on automatic detection SetAutoDetectSettings(true); } } finally { Marshal.FreeHGlobal(ieProxyConfig.Proxy); Marshal.FreeHGlobal(ieProxyConfig.ProxyBypass); Marshal.FreeHGlobal(ieProxyConfig.AutoConfigUrl); } GlobalLog.Leave("WinHttpWebProxyBuilder#" + ValidationHelper.HashString(this) + "::BuildInternal()"); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; namespace System.Net { internal sealed class WinHttpWebProxyBuilder : WebProxyDataBuilder { protected override void BuildInternal() { GlobalLog.Enter("WinHttpWebProxyBuilder#" + ValidationHelper.HashString(this) + "::BuildInternal()"); UnsafeNclNativeMethods.WinHttp.WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ieProxyConfig = new UnsafeNclNativeMethods.WinHttp.WINHTTP_CURRENT_USER_IE_PROXY_CONFIG(); // Make sure the native strings get freed, even if some unexpected exception occurs. RuntimeHelpers.PrepareConstrainedRegions(); try { if (UnsafeNclNativeMethods.WinHttp.WinHttpGetIEProxyConfigForCurrentUser(ref ieProxyConfig)) { string proxy = null; string proxyByPass = null; string autoConfigUrl = null; proxy = Marshal.PtrToStringUni(ieProxyConfig.Proxy); proxyByPass = Marshal.PtrToStringUni(ieProxyConfig.ProxyBypass); autoConfigUrl = Marshal.PtrToStringUni(ieProxyConfig.AutoConfigUrl); // note that ieProxyConfig.Proxy will be null if "use a proxy server" flag is turned off, even if // the user specified a proxy address. When we read directly from the Registry we need to check // for ProxyTypeFlags.PROXY_TYPE_PROXY. WinHttp does this for us and if the flag is not set, // ieProxyConfig.Proxy will be null. SetProxyAndBypassList(proxy, proxyByPass); SetAutoDetectSettings(ieProxyConfig.AutoDetect); // similar to comment above: ieProxyConfig.AutoConfigUrl will only be set if "automatically detect // settings" flag is set. We don't need to check ProxyTypeFlags.PROXY_TYPE_AUTO_PROXY_URL; WinHttp // takes care of it and sets AutoConfigUrl to null if the flag is not set, regardless of the actual // config script string. SetAutoProxyUrl(autoConfigUrl); } else { int errorCode = Marshal.GetLastWin32Error(); if (errorCode == Microsoft.Win32.NativeMethods.ERROR_NOT_ENOUGH_MEMORY) { throw new OutOfMemoryException(); } // if API call fails, rely on automatic detection SetAutoDetectSettings(true); } } finally { Marshal.FreeHGlobal(ieProxyConfig.Proxy); Marshal.FreeHGlobal(ieProxyConfig.ProxyBypass); Marshal.FreeHGlobal(ieProxyConfig.AutoConfigUrl); } GlobalLog.Leave("WinHttpWebProxyBuilder#" + ValidationHelper.HashString(this) + "::BuildInternal()"); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TextAdaptor.cs
- mediaeventargs.cs
- BuildProvider.cs
- SoapFormatExtensions.cs
- XmlSchemaImporter.cs
- ImportDesigner.xaml.cs
- SQLBytes.cs
- LinkUtilities.cs
- GeneralTransformGroup.cs
- BuilderInfo.cs
- ActivityBuilderHelper.cs
- WmpBitmapDecoder.cs
- ProfessionalColors.cs
- DocumentPageView.cs
- GridViewDeleteEventArgs.cs
- DataTableNameHandler.cs
- MailWebEventProvider.cs
- Stylus.cs
- EditorPartChrome.cs
- ToolStripSeparator.cs
- DependencyProperty.cs
- CustomCategoryAttribute.cs
- columnmapfactory.cs
- TimeZoneInfo.cs
- LocationChangedEventArgs.cs
- DataGridViewUtilities.cs
- SystemNetHelpers.cs
- RegisteredArrayDeclaration.cs
- safex509handles.cs
- TdsRecordBufferSetter.cs
- ContentDisposition.cs
- RemoteCryptoTokenProvider.cs
- InheritanceRules.cs
- ZipIOZip64EndOfCentralDirectoryLocatorBlock.cs
- NodeFunctions.cs
- Converter.cs
- Membership.cs
- TransactionValidationBehavior.cs
- DescendantBaseQuery.cs
- CodeDomConfigurationHandler.cs
- Pkcs7Recipient.cs
- HttpListenerResponse.cs
- mediaeventargs.cs
- XmlTextReaderImpl.cs
- XmlSchemaChoice.cs
- FloaterBaseParagraph.cs
- PageCache.cs
- Mapping.cs
- WpfKnownTypeInvoker.cs
- DataGridViewAutoSizeColumnsModeEventArgs.cs
- DataStreams.cs
- WebException.cs
- StringComparer.cs
- SourceLineInfo.cs
- XmlCollation.cs
- UpdatePanelTrigger.cs
- CanExecuteRoutedEventArgs.cs
- RtfToXamlReader.cs
- ByteStorage.cs
- SettingsPropertyIsReadOnlyException.cs
- CompModSwitches.cs
- CTreeGenerator.cs
- MenuItemStyle.cs
- ImmutableObjectAttribute.cs
- EncryptedKey.cs
- VariableElement.cs
- DefaultPrintController.cs
- WebPartEditorOkVerb.cs
- BulletChrome.cs
- HMACSHA1.cs
- ButtonAutomationPeer.cs
- SchemaCollectionPreprocessor.cs
- XmlRawWriter.cs
- Crc32Helper.cs
- ClientTargetCollection.cs
- SpecularMaterial.cs
- TypedElement.cs
- EntityCommandExecutionException.cs
- PeerApplicationLaunchInfo.cs
- DocumentationServerProtocol.cs
- AsmxEndpointPickerExtension.cs
- CollectionViewSource.cs
- SystemIcons.cs
- EdmComplexPropertyAttribute.cs
- ResourceDescriptionAttribute.cs
- BoundField.cs
- EncoderNLS.cs
- Section.cs
- HtmlUtf8RawTextWriter.cs
- ClientProtocol.cs
- SchemaNotation.cs
- SystemBrushes.cs
- FrameSecurityDescriptor.cs
- FormCollection.cs
- TextRangeBase.cs
- MonthCalendar.cs
- SettingsContext.cs
- CircleHotSpot.cs
- LongTypeConverter.cs
- ScriptManagerProxy.cs