Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / Net / System / Net / _WinHttpWebProxyDataBuilder.cs / 1 / _WinHttpWebProxyDataBuilder.cs
using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; 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(); if (UnsafeNclNativeMethods.WinHttp.WinHttpGetIEProxyConfigForCurrentUser(ref ieProxyConfig)) { string proxy = null; string proxyByPass = null; string autoConfigUrl = null; try { 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); } finally { FreeStr(ieProxyConfig.Proxy); FreeStr(ieProxyConfig.ProxyBypass); FreeStr(ieProxyConfig.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); } GlobalLog.Leave("WinHttpWebProxyBuilder#" + ValidationHelper.HashString(this) + "::BuildInternal()"); } private void FreeStr(IntPtr intPtr) { if (intPtr != IntPtr.Zero) { Marshal.FreeHGlobal(intPtr); } } } } // 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; 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(); if (UnsafeNclNativeMethods.WinHttp.WinHttpGetIEProxyConfigForCurrentUser(ref ieProxyConfig)) { string proxy = null; string proxyByPass = null; string autoConfigUrl = null; try { 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); } finally { FreeStr(ieProxyConfig.Proxy); FreeStr(ieProxyConfig.ProxyBypass); FreeStr(ieProxyConfig.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); } GlobalLog.Leave("WinHttpWebProxyBuilder#" + ValidationHelper.HashString(this) + "::BuildInternal()"); } private void FreeStr(IntPtr intPtr) { if (intPtr != IntPtr.Zero) { Marshal.FreeHGlobal(intPtr); } } } } // 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
- ExpressionBuilder.cs
- ButtonBase.cs
- NavigationExpr.cs
- ResXDataNode.cs
- DataListAutoFormat.cs
- FormViewActionList.cs
- MenuItem.cs
- DefaultValueTypeConverter.cs
- TargetParameterCountException.cs
- HashCryptoHandle.cs
- InputScopeNameConverter.cs
- SchemaImporterExtensionElement.cs
- RectConverter.cs
- WebPartEventArgs.cs
- PolygonHotSpot.cs
- ListenerElementsCollection.cs
- AdRotator.cs
- ManagedFilter.cs
- Msec.cs
- TypeUnloadedException.cs
- VersionedStreamOwner.cs
- ADMembershipProvider.cs
- TileBrush.cs
- UIElement.cs
- CharacterString.cs
- StylusTip.cs
- FixedSOMPageConstructor.cs
- DatagridviewDisplayedBandsData.cs
- KeyNotFoundException.cs
- SqlExpander.cs
- FolderBrowserDialog.cs
- InplaceBitmapMetadataWriter.cs
- PathFigureCollection.cs
- SystemIPInterfaceStatistics.cs
- PointCollectionValueSerializer.cs
- CompositeActivityTypeDescriptorProvider.cs
- ExtensionWindowHeader.cs
- OracleCommandBuilder.cs
- InputMethodStateChangeEventArgs.cs
- XmlCharType.cs
- TextOptionsInternal.cs
- DataGridViewColumn.cs
- NumberSubstitution.cs
- CodeParameterDeclarationExpression.cs
- PrePrepareMethodAttribute.cs
- BufferBuilder.cs
- AuthenticationManager.cs
- TaskSchedulerException.cs
- ToolStripArrowRenderEventArgs.cs
- PersistStreamTypeWrapper.cs
- IHttpResponseInternal.cs
- SqlServices.cs
- MsmqIntegrationBinding.cs
- DataControlReferenceCollection.cs
- ColumnWidthChangingEvent.cs
- ImageMap.cs
- ListViewGroup.cs
- XmlDocumentSerializer.cs
- AutoResetEvent.cs
- XmlChoiceIdentifierAttribute.cs
- CompiledRegexRunnerFactory.cs
- IPHostEntry.cs
- KeyedHashAlgorithm.cs
- Attributes.cs
- EventProviderWriter.cs
- TraceContextEventArgs.cs
- WorkflowServiceHostFactory.cs
- __Filters.cs
- WebPartManagerInternals.cs
- TextWriter.cs
- XmlDataCollection.cs
- DataSetUtil.cs
- SqlProvider.cs
- ComPlusTypeLoader.cs
- InfoCardCryptoHelper.cs
- DataGridPageChangedEventArgs.cs
- Set.cs
- TypeBinaryExpression.cs
- OdbcCommandBuilder.cs
- AppDomain.cs
- CustomAssemblyResolver.cs
- NativeMethods.cs
- ValueSerializerAttribute.cs
- DesignTimeXamlWriter.cs
- SparseMemoryStream.cs
- DataGridTablesFactory.cs
- EntityViewGenerationConstants.cs
- SafeThreadHandle.cs
- HyperLinkColumn.cs
- TextFormatterContext.cs
- InheritablePropertyChangeInfo.cs
- ContextMarshalException.cs
- AssemblyCache.cs
- TdsRecordBufferSetter.cs
- ModelServiceImpl.cs
- DynamicResourceExtension.cs
- DataKeyArray.cs
- HtmlTextArea.cs
- Permission.cs
- SystemColors.cs