HostingEnvironmentWrapper.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Activation / HostingEnvironmentWrapper.cs / 1 / HostingEnvironmentWrapper.cs

                            //---------------------------------------------------------------------------- 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//---------------------------------------------------------------------------
namespace System.ServiceModel
{ 
    using System;
    using System.Security; 
    using System.Security.Permissions; 
    using System.Web.Hosting;
    using System.Web; 
    using System.Runtime.CompilerServices;

    // wrapper class that helps with partial trust analysis
    // -- HostingEnvironment does a number of Demands and LinkDemands 
    // -- this wrapper encapsulates access into "Safe" and "Unsafe" methods that do the appropriate asserts
    // -- it is recommended that ALL HostingEnvironment access go through this class 
    // -- "Safe" methods are [SecurityCritical, SecurityTreatAsSafe] or not [SecurityCritical] 
    // -- "Unsafe" methods are [SecurityCritical]
    // -- because each method does precisely one access, we use declarative asserts for clarity 
    static class HostingEnvironmentWrapper
    {
        public static string /*Safe*/ApplicationVirtualPath
        { 
            get { return HostingEnvironment.ApplicationVirtualPath; }
        } 
 
        public static bool /*Safe*/IsHosted
        { 
            get { return HostingEnvironment.IsHosted; }
        }

        ///  
        /// Critical - calls getters with LinkDemands in ASP .NET objects
        /// Safe - does not leak control or mutable/harmful data, no potential for harm 
        ///  
        [SecurityCritical, SecurityTreatAsSafe]
        public static VirtualPathProvider /*Safe*/VirtualPathProvider 
        {
            get { return HostingEnvironment.VirtualPathProvider; }
        }
 

        ///  
        /// Critical - calls getters with LinkDemands in ASP .NET objects 
        /// Safe - does not leak control or mutable/harmful data, no potential for harm
        ///  
        [SecurityCritical, SecurityTreatAsSafe]
        [MethodImpl(MethodImplOptions.NoInlining)]
        public static void /*Safe*/DecrementBusyCount()
        { 
            HostingEnvironment.DecrementBusyCount();
        } 
 
        // demands SecurityPermission(ControlPrincipal) -- use Unsafe version to assert
        public static IDisposable /*Safe*/Impersonate() 
        {
            return HostingEnvironment.Impersonate();
        }
 
        // demands SecurityPermission(Unrestricted) -- use Unsafe version to assert
        public static IDisposable /*Safe*/Impersonate(IntPtr token) 
        { 
            return HostingEnvironment.Impersonate(token);
        } 

        /// 
        /// Critical - calls getters with LinkDemands in ASP .NET objects
        /// Safe - does not leak control or mutable/harmful data, no potential for harm 
        /// 
        [SecurityCritical, SecurityTreatAsSafe] 
        [MethodImpl(MethodImplOptions.NoInlining)] 
        public static void /*Safe*/IncrementBusyCount()
        { 
            HostingEnvironment.IncrementBusyCount();
        }

        public static string /*Safe*/MapPath(string virtualPath) 
        {
            return HostingEnvironment.MapPath(virtualPath); 
        } 

        public static string UnsafeApplicationID 
        {
            /// 
            /// Critical - Asserts SecurityPermission in order to call HostingEnvironment.get_ApplicationID
            ///  
            [SecurityCritical]
            [AspNetHostingPermission(System.Security.Permissions.SecurityAction.Assert, Level = AspNetHostingPermissionLevel.High)] 
            get { return HostingEnvironment.ApplicationID; } 
        }
 
        /// 
        /// Critical - Asserts SecurityPermission in order to call HostingEnvironment.UnsafeImpersonate
        /// 
        [SecurityCritical] 
        [SecurityPermission(SecurityAction.Assert, ControlPrincipal = true)]
        public static IDisposable UnsafeImpersonate() 
        { 
            return HostingEnvironment.Impersonate();
        } 

        /// 
        /// Critical - Asserts SecurityPermission in order to call HostingEnvironment.UnsafeImpersonate
        ///  
        [SecurityCritical]
        [SecurityPermission(SecurityAction.Assert, Unrestricted = true)] 
        public static IDisposable UnsafeImpersonate(IntPtr token) 
        {
            return HostingEnvironment.Impersonate(token); 
        }

        /// 
        /// Critical - Asserts SecurityPermission in order to call HostingEnvironment.RegisterObject 
        /// 
        [SecurityCritical] 
        [SecurityPermission(SecurityAction.Assert, Unrestricted = true)] 
        public static void UnsafeRegisterObject(IRegisteredObject target)
        { 
            HostingEnvironment.RegisterObject(target);
        }

        ///  
        /// Critical - Asserts SecurityPermission in order to call HostingEnvironment.UnregisterObject
        ///  
        [SecurityCritical] 
        [SecurityPermission(SecurityAction.Assert, Unrestricted = true)]
        public static void UnsafeUnregisterObject(IRegisteredObject target) 
        {
            HostingEnvironment.UnregisterObject(target);
        }
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK