Permission.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / xsp / System / Web / Util / Permission.cs / 1 / Permission.cs

                            //------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 

/* 
 * 
 * Copyright (c) 1998-1999, Microsoft Corporation
 * 
 */

namespace System.Web.Util {
    using System.Security.Permissions; 
    using System.Security;
    using System.Data.SqlClient; 
 
    static class Permission {
        internal static bool HasSqlClientPermission() { 
            NamedPermissionSet  permissionset = HttpRuntime.NamedPermissionSet;

            // If we don't have a NamedPermissionSet, we're in full trust
            if (permissionset == null) 
                return true;
 
            // Check that the user has unrestricted SqlClientPermission 
            IPermission allowedPermission = permissionset.GetPermission(typeof(SqlClientPermission));
 
            if (allowedPermission == null) {
                return false;
            }
 
            IPermission askedPermission = null;
            try { 
                askedPermission = new SqlClientPermission(PermissionState.Unrestricted); 
            }
            catch { 
                return false;
            }

            return askedPermission.IsSubsetOf(allowedPermission); 
        }
 
    } 
}

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

/* 
 * 
 * Copyright (c) 1998-1999, Microsoft Corporation
 * 
 */

namespace System.Web.Util {
    using System.Security.Permissions; 
    using System.Security;
    using System.Data.SqlClient; 
 
    static class Permission {
        internal static bool HasSqlClientPermission() { 
            NamedPermissionSet  permissionset = HttpRuntime.NamedPermissionSet;

            // If we don't have a NamedPermissionSet, we're in full trust
            if (permissionset == null) 
                return true;
 
            // Check that the user has unrestricted SqlClientPermission 
            IPermission allowedPermission = permissionset.GetPermission(typeof(SqlClientPermission));
 
            if (allowedPermission == null) {
                return false;
            }
 
            IPermission askedPermission = null;
            try { 
                askedPermission = new SqlClientPermission(PermissionState.Unrestricted); 
            }
            catch { 
                return false;
            }

            return askedPermission.IsSubsetOf(allowedPermission); 
        }
 
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.

                        

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