Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Net / System / Net / HttpSysSettings.cs / 1305376 / HttpSysSettings.cs
using System;
using System.Diagnostics;
using System.Text;
using System.Collections.Generic;
using System.Globalization;
using System.Security.Permissions;
using Microsoft.Win32;
using System.IO;
using System.Security;
namespace System.Net
{
internal static class HttpSysSettings
{
private const string httpSysParametersKey = @"System\CurrentControlSet\Services\HTTP\Parameters";
private const bool enableNonUtf8Default = true;
private const bool favorUtf8Default = true;
private const string enableNonUtf8Name = "EnableNonUtf8";
private const string favorUtf8Name = "FavorUtf8";
private static bool enableNonUtf8;
private static bool favorUtf8;
static HttpSysSettings()
{
enableNonUtf8 = enableNonUtf8Default;
favorUtf8 = favorUtf8Default;
ReadHttpSysRegistrySettings();
}
public static bool EnableNonUtf8
{
get { return enableNonUtf8; }
}
public static bool FavorUtf8
{
get { return favorUtf8; }
}
[RegistryPermission(SecurityAction.Assert, Read = @"HKEY_LOCAL_MACHINE\" + httpSysParametersKey)]
private static void ReadHttpSysRegistrySettings()
{
try
{
RegistryKey httpSysParameters = Registry.LocalMachine.OpenSubKey(httpSysParametersKey);
if (httpSysParameters == null)
{
LogWarning("ReadHttpSysRegistrySettings", SR.net_log_listener_httpsys_registry_null,
httpSysParametersKey);
}
else
{
using (httpSysParameters)
{
enableNonUtf8 = ReadRegistryValue(httpSysParameters, enableNonUtf8Name, enableNonUtf8Default);
favorUtf8 = ReadRegistryValue(httpSysParameters, favorUtf8Name, favorUtf8Default);
}
}
}
catch (SecurityException e)
{
LogRegistryException("ReadHttpSysRegistrySettings", e);
}
catch (ObjectDisposedException e)
{
LogRegistryException("ReadHttpSysRegistrySettings", e);
}
}
private static bool ReadRegistryValue(RegistryKey key, string valueName, bool defaultValue)
{
Debug.Assert(key != null, "'key' must not be null");
try
{
// This check will throw an IOException if keyName doesn't exist. That's OK, we return the
// default value.
if (key.GetValueKind(valueName) == RegistryValueKind.DWord)
{
// At this point we know the Registry value exists and it must be valid (any DWORD value
// can be converted to a bool).
return Convert.ToBoolean(key.GetValue(valueName), CultureInfo.InvariantCulture);
}
}
catch (UnauthorizedAccessException e)
{
LogRegistryException("ReadRegistryValue", e);
}
catch (IOException e)
{
LogRegistryException("ReadRegistryValue", e);
}
catch (SecurityException e)
{
LogRegistryException("ReadRegistryValue", e);
}
catch (ObjectDisposedException e)
{
LogRegistryException("ReadRegistryValue", e);
}
return defaultValue;
}
private static void LogRegistryException(string methodName, Exception e)
{
LogWarning(methodName, SR.net_log_listener_httpsys_registry_error, httpSysParametersKey, e);
}
private static void LogWarning(string methodName, string message, params object[] args)
{
if (Logging.On)
{
Logging.PrintWarning(Logging.HttpListener, typeof(HttpSysSettings), methodName,
SR.GetString(message, args));
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
using System;
using System.Diagnostics;
using System.Text;
using System.Collections.Generic;
using System.Globalization;
using System.Security.Permissions;
using Microsoft.Win32;
using System.IO;
using System.Security;
namespace System.Net
{
internal static class HttpSysSettings
{
private const string httpSysParametersKey = @"System\CurrentControlSet\Services\HTTP\Parameters";
private const bool enableNonUtf8Default = true;
private const bool favorUtf8Default = true;
private const string enableNonUtf8Name = "EnableNonUtf8";
private const string favorUtf8Name = "FavorUtf8";
private static bool enableNonUtf8;
private static bool favorUtf8;
static HttpSysSettings()
{
enableNonUtf8 = enableNonUtf8Default;
favorUtf8 = favorUtf8Default;
ReadHttpSysRegistrySettings();
}
public static bool EnableNonUtf8
{
get { return enableNonUtf8; }
}
public static bool FavorUtf8
{
get { return favorUtf8; }
}
[RegistryPermission(SecurityAction.Assert, Read = @"HKEY_LOCAL_MACHINE\" + httpSysParametersKey)]
private static void ReadHttpSysRegistrySettings()
{
try
{
RegistryKey httpSysParameters = Registry.LocalMachine.OpenSubKey(httpSysParametersKey);
if (httpSysParameters == null)
{
LogWarning("ReadHttpSysRegistrySettings", SR.net_log_listener_httpsys_registry_null,
httpSysParametersKey);
}
else
{
using (httpSysParameters)
{
enableNonUtf8 = ReadRegistryValue(httpSysParameters, enableNonUtf8Name, enableNonUtf8Default);
favorUtf8 = ReadRegistryValue(httpSysParameters, favorUtf8Name, favorUtf8Default);
}
}
}
catch (SecurityException e)
{
LogRegistryException("ReadHttpSysRegistrySettings", e);
}
catch (ObjectDisposedException e)
{
LogRegistryException("ReadHttpSysRegistrySettings", e);
}
}
private static bool ReadRegistryValue(RegistryKey key, string valueName, bool defaultValue)
{
Debug.Assert(key != null, "'key' must not be null");
try
{
// This check will throw an IOException if keyName doesn't exist. That's OK, we return the
// default value.
if (key.GetValueKind(valueName) == RegistryValueKind.DWord)
{
// At this point we know the Registry value exists and it must be valid (any DWORD value
// can be converted to a bool).
return Convert.ToBoolean(key.GetValue(valueName), CultureInfo.InvariantCulture);
}
}
catch (UnauthorizedAccessException e)
{
LogRegistryException("ReadRegistryValue", e);
}
catch (IOException e)
{
LogRegistryException("ReadRegistryValue", e);
}
catch (SecurityException e)
{
LogRegistryException("ReadRegistryValue", e);
}
catch (ObjectDisposedException e)
{
LogRegistryException("ReadRegistryValue", e);
}
return defaultValue;
}
private static void LogRegistryException(string methodName, Exception e)
{
LogWarning(methodName, SR.net_log_listener_httpsys_registry_error, httpSysParametersKey, e);
}
private static void LogWarning(string methodName, string message, params object[] args)
{
if (Logging.On)
{
Logging.PrintWarning(Logging.HttpListener, typeof(HttpSysSettings), methodName,
SR.GetString(message, args));
}
}
}
}
// 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
- ScalarConstant.cs
- TextRenderer.cs
- RangeContentEnumerator.cs
- ProgressPage.cs
- COM2Enum.cs
- Operator.cs
- CriticalExceptions.cs
- HealthMonitoringSectionHelper.cs
- FormsAuthentication.cs
- _ConnectionGroup.cs
- ResourcePermissionBase.cs
- AddInAttribute.cs
- ListViewTableRow.cs
- PropertyReferenceSerializer.cs
- ReadOnlyCollectionBase.cs
- DragDrop.cs
- SerializerWriterEventHandlers.cs
- DataListItem.cs
- SequentialUshortCollection.cs
- ResourceSet.cs
- HttpGetServerProtocol.cs
- DbConnectionHelper.cs
- InlineCategoriesDocument.cs
- PageStatePersister.cs
- SystemUdpStatistics.cs
- TextElementEditingBehaviorAttribute.cs
- TemplateControl.cs
- SecUtil.cs
- OperandQuery.cs
- WinFormsUtils.cs
- Crc32.cs
- BaseAsyncResult.cs
- CodeSnippetExpression.cs
- initElementDictionary.cs
- SqlLiftWhereClauses.cs
- ProfessionalColors.cs
- ClientScriptItemCollection.cs
- PtsHelper.cs
- TemplateEditingVerb.cs
- Expander.cs
- NegatedConstant.cs
- ProcessManager.cs
- TransactedBatchingElement.cs
- InfoCardAsymmetricCrypto.cs
- MissingManifestResourceException.cs
- MsmqIntegrationBindingElement.cs
- PropertyDescriptor.cs
- GeometryModel3D.cs
- TreeNodeCollection.cs
- DeobfuscatingStream.cs
- WebFaultClientMessageInspector.cs
- WorkflowInlining.cs
- HiddenFieldDesigner.cs
- URI.cs
- LayoutExceptionEventArgs.cs
- XmlSchemaGroup.cs
- DataGridViewComboBoxColumn.cs
- SamlConditions.cs
- SafeRightsManagementPubHandle.cs
- IndexerNameAttribute.cs
- ReflectTypeDescriptionProvider.cs
- SettingsPropertyValueCollection.cs
- PassportIdentity.cs
- Size3DValueSerializer.cs
- AppDomainShutdownMonitor.cs
- CoTaskMemUnicodeSafeHandle.cs
- SimpleLine.cs
- CorrelationValidator.cs
- ImmutablePropertyDescriptorGridEntry.cs
- HostSecurityManager.cs
- ObfuscationAttribute.cs
- CompiledQuery.cs
- CornerRadiusConverter.cs
- HostedNamedPipeTransportManager.cs
- TextAnchor.cs
- DetailsViewInsertedEventArgs.cs
- JapaneseCalendar.cs
- WizardStepBase.cs
- DrawListViewColumnHeaderEventArgs.cs
- SafeArrayRankMismatchException.cs
- TdsRecordBufferSetter.cs
- PenContexts.cs
- WindowsNonControl.cs
- StrongNameSignatureInformation.cs
- Interop.cs
- httpstaticobjectscollection.cs
- Translator.cs
- XmlDataLoader.cs
- ParameterInfo.cs
- AddInPipelineAttributes.cs
- CommandManager.cs
- DPTypeDescriptorContext.cs
- ChannelDispatcher.cs
- mediaeventargs.cs
- InputLangChangeEvent.cs
- SystemTcpConnection.cs
- CuspData.cs
- WebPartZoneBase.cs
- configsystem.cs
- TdsParserStateObject.cs