/WCFWebApi/src/Microsoft.ServiceModel.Internal/Microsoft/ServiceModel/Activation/AspNetEnvironment.cs
C# | 66 lines | 50 code | 8 blank | 8 comment | 6 complexity | 01887987575682f245072553e8ad89db MD5 | raw file
Possible License(s): CC-BY-SA-3.0, Apache-2.0
- // <copyright>
- // Copyright (c) Microsoft Corporation. All rights reserved.
- // </copyright>
-
- namespace Microsoft.ServiceModel.Activation
- {
- using System.Configuration;
- using System.Diagnostics.CodeAnalysis;
- using System.ServiceModel.Channels;
- using Microsoft.Server.Common;
-
- internal class AspNetEnvironment
- {
- public const string HostingMessagePropertyName = "webhost";
-
- private const string HostingMessagePropertyTypeName = "System.ServiceModel.Activation.HostingMessageProperty";
- private static AspNetEnvironment current;
- private static object thisLock = new object();
-
- public static AspNetEnvironment Current
- {
- get
- {
- if (current == null)
- {
- lock (thisLock)
- {
- if (current == null)
- {
- current = new AspNetEnvironment();
- }
- }
- }
-
- return current;
- }
- }
-
- // ALTERED_FOR_PORT:
- // The GetHostingProperty() code below is an altered implementation from the System.ServiceModel.Activation.HostedAspNetEnvironment class.
- // The original implementation casts the hostingProperty to type System.ServiceModel.Activation.HostingMessageProperty. However,
- // this class is internal sealed, therefore we simply check the type name.
- [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "This is existing public API")]
- public object GetHostingProperty(Message message)
- {
- object hostingProperty;
- if (message.Properties.TryGetValue(HostingMessagePropertyName, out hostingProperty))
- {
- string hostingPropertyName = hostingProperty.GetType().FullName;
- if (string.Equals(hostingPropertyName, HostingMessagePropertyTypeName, System.StringComparison.Ordinal))
- {
- return hostingProperty;
- }
- }
-
- return null;
- }
-
- // TODO: CSDMAIN 205599 -- verify this approach works under IIS
- [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "This is existing public API")]
- public object GetConfigurationSection(string sectionPath)
- {
- return ConfigurationManager.GetSection(sectionPath);
- }
- }
- }