Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- RouteUrlExpressionBuilder.cs
- TypeDelegator.cs
- GeometryValueSerializer.cs
- DockPanel.cs
- ViewPort3D.cs
- xmlsaver.cs
- ChangeNode.cs
- DataGridHelper.cs
- PopupControlService.cs
- Odbc32.cs
- SQLDouble.cs
- HiddenFieldPageStatePersister.cs
- SoapDocumentMethodAttribute.cs
- RecognizerBase.cs
- FirewallWrapper.cs
- MethodSignatureGenerator.cs
- ISO2022Encoding.cs
- QilName.cs
- ObjectContextServiceProvider.cs
- NumberAction.cs
- SMSvcHost.cs
- WindowHideOrCloseTracker.cs
- DataColumnMappingCollection.cs
- ReversePositionQuery.cs
- NameValueConfigurationCollection.cs
- HttpValueCollection.cs
- ConfigurationValues.cs
- EntityModelBuildProvider.cs
- PropertyNames.cs
- DbConnectionPoolIdentity.cs
- FilterQuery.cs
- URLBuilder.cs
- sitestring.cs
- LinearKeyFrames.cs
- RecipientIdentity.cs
- AssemblyBuilderData.cs
- XmlSchemaValidator.cs
- DeobfuscatingStream.cs
- Freezable.cs
- FormView.cs
- WebPartDisplayModeEventArgs.cs
- BindingContext.cs
- WizardPanelChangingEventArgs.cs
- InstanceData.cs
- QuadraticBezierSegment.cs
- DataGridViewCheckBoxCell.cs
- ParameterModifier.cs
- CachedResourceDictionaryExtension.cs
- __Filters.cs
- UnsafeNativeMethodsTablet.cs
- LogSwitch.cs
- SubMenuStyleCollection.cs
- dbdatarecord.cs
- dbenumerator.cs
- CompilationUtil.cs
- X509Certificate.cs
- HtmlInputRadioButton.cs
- PageDeviceFont.cs
- HandleCollector.cs
- ErrorRuntimeConfig.cs
- TraceHandlerErrorFormatter.cs
- CommandField.cs
- UnsafeNetInfoNativeMethods.cs
- MatrixIndependentAnimationStorage.cs
- PolyLineSegmentFigureLogic.cs
- LoginView.cs
- BrushConverter.cs
- FixedFlowMap.cs
- GridViewCommandEventArgs.cs
- VisualCollection.cs
- RetrieveVirtualItemEventArgs.cs
- Transform3D.cs
- XmlComment.cs
- SimpleHandlerFactory.cs
- WebPartHelpVerb.cs
- AudioLevelUpdatedEventArgs.cs
- EntitySqlQueryBuilder.cs
- XmlSchemaExternal.cs
- handlecollector.cs
- WebPartConnectionsDisconnectVerb.cs
- MetadataHelper.cs
- X509AsymmetricSecurityKey.cs
- StringFreezingAttribute.cs
- GPRECTF.cs
- DrawingAttributeSerializer.cs
- Processor.cs
- WindowsSpinner.cs
- ErrorWebPart.cs
- QueryOptionExpression.cs
- SHA256Managed.cs
- MarginsConverter.cs
- InkCanvasSelectionAdorner.cs
- ApplyImportsAction.cs
- XmlAttributeCollection.cs
- TableCell.cs
- FontSource.cs
- DateTimeFormat.cs
- SafeHandles.cs
- NamespaceQuery.cs
- ValidationErrorCollection.cs