⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webadminpage.cs

📁 《圣殿祭司的ASP.NET 2.0开发详解——使用C#》光盘内容.包含了书籍所含的源代码.非常经典的一本asp.net2.0的书籍
💻 CS
📖 第 1 页 / 共 4 页
字号:
//------------------------------------------------------------------------------
// <copyright file="WebAdminPage.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//------------------------------------------------------------------------------

namespace System.Web.Administration {
    using System.Collections;
    using System.Collections.Specialized;
    using System.Configuration;
    using System.Diagnostics;
    using System.Globalization;
    using System.Reflection;
    using System.Security;
    using System.Text;
    using System.Web;
    using System.Web.Configuration;
    using System.Web.Hosting;
    using System.Web.Management;
    using System.Web.Security;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Security.Permissions;

    [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
    public class WebAdminPage : Page {
        private const string APP_PATH = "WebAdminApplicationPath";
        private const string APP_PHYSICAL_PATH = "WebAdminPhysicalPath";
        private const string CURRENT_EXCEPTION = "WebAdminCurrentException";
        private const string CURRENT_PROVIDER = "WebAdminCurrentProvider";
        private const string CURRENT_ROLE = "WebAdminCurrentRoleName";
        private const string CURRENT_USER = "WebAdminCurrentUser";
        private const string CURRENT_USER_COLLECTION = "WebAdminUserCollection";
        private const string URL_STACK = "WebAdminUrlStack";
        private string _directionality;
        private NavigationBar _navigationBar = null;

        public WebAdminRemotingManager RemotingManager {
            get {
                return (WebAdminRemotingManager)Session["WebAdminRemotingManager"];
            }
        }

        public object CallWebAdminHelperMethod(bool isMembership, string methodName, object[] parameters, Type[] paramTypes) {
            object returnObject = null;
            object tempObject = null;

            tempObject = RemotingManager.ConfigurationHelperInstance;
            if (tempObject != null) {
                string methodName2 = string.Empty;
                string typeFullName = WebAdminRemotingManager.AssemblyVersionString;
                if (isMembership) {
                    methodName2 = "CallMembershipProviderMethod";
                } else {
                    methodName2 = "CallRoleProviderMethod";
                }
                Type tempType = Type.GetType(typeFullName);

                BindingFlags allBindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
                MethodInfo method = tempType.GetMethod(methodName2, allBindingFlags);
                if (method != null) {
                    object[] newParameters = new object[]{methodName, parameters, paramTypes};
                    try {
                        object[] returnArrayObj = (object[]) method.Invoke(tempObject, newParameters);
                        if (returnArrayObj != null) {
                            returnObject = returnArrayObj[0];
                        }
                    } catch (Exception ex) {
                        if (ex.InnerException != null) {
                            if (ex.InnerException.InnerException != null) {
                                throw new WebAdminException(ex.InnerException.InnerException.Message);
                            } else {
                                throw new WebAdminException(ex.InnerException.Message);
                            }
                        } else {
                            throw new WebAdminException(ex.Message);
                        }
                    }
                }
            }

            return returnObject;
        }

        public VirtualDirectory GetVirtualDirectory(string virtualDir) {
            return RemotingManager.GetVirtualDirectory(virtualDir);
        }

        public void SaveConfig(Configuration config) {
            RemotingManager.ShutdownTargetApplication();
            config.NamespaceDeclared = true;

            // check if session expired
            if (String.IsNullOrEmpty(ApplicationPath) || String.IsNullOrEmpty((string)Session[APP_PHYSICAL_PATH])) {
                Server.Transfer("~/home2.aspx");
            }

            config.Save(ConfigurationSaveMode.Minimal);
        }


        public string ApplicationPath {
            get {
                return (string)Session[APP_PATH];
            }
        }

        protected virtual bool CanSetApplicationPath {
            get {
                return false;
            }
        }

        protected string CurrentProvider {
            get {
                object obj = (object)Session[CURRENT_PROVIDER];
                if (obj != null) {
                    return (string)Session[CURRENT_PROVIDER];
                } 
                return String.Empty;
            }
            set {
                Session[CURRENT_PROVIDER] = value;
            }
        }

        protected string CurrentRequestUrl {
            get {
                Stack stack = (Stack) Session[URL_STACK];
                if (stack != null && stack.Count > 0) {
                    return(string)stack.Peek();
                }
                return string.Empty;
            }
        }

        protected string CurrentRole {
            get {
                object obj = (object)Session[CURRENT_ROLE];
                if (obj != null) {
                    return (string)Session[CURRENT_ROLE];
                }
                return String.Empty;
            }
            set {
                Session[CURRENT_ROLE] = value;
            }
        }

        protected string CurrentUser {
            get {
                object obj = (string)Session[CURRENT_USER];
                if (obj != null) {
                    return (string)Session[CURRENT_USER];
                }
                return String.Empty;
            }
            set {
                Session[CURRENT_USER] = value;
            }
        }

        public string Directionality {
            get {
                if (String.IsNullOrEmpty(_directionality)) {
                    _directionality = ((string) GetGlobalResourceObject("GlobalResources", "HtmlDirectionality")).ToLower();
                }
                return _directionality;
            }
        }

        public HorizontalAlign DirectionalityHorizontalAlign {
           get {
                if (Directionality == "rtl") {
                    return HorizontalAlign.Right;
                } else {
                    return HorizontalAlign.Left;
                }
           }
        }

        public Hashtable UserCollection {
            get {
                Hashtable table = (Hashtable) Session[CURRENT_USER_COLLECTION];
                if (table == null) {
                    Session[CURRENT_USER_COLLECTION] = table = new Hashtable();
                }
                return table;
            }
        }

        public NavigationBar NavigationBar {
            get {
                return _navigationBar;
            }
            set {
                _navigationBar = value;
            }
        }

        public string UnderscoreProductVersion {
            get {
                return Environment.Version.ToString(3).Replace(".", "_");
            }
        }

        public static Exception GetCurrentException(HttpContext c) {
            return (Exception)c.Session[CURRENT_EXCEPTION];
        }

        public static void SetCurrentException(HttpContext c, Exception ex) {
            c.Session[CURRENT_EXCEPTION] = ex;
        }

        protected void ClearBadStackPage() {
            Stack stack = (Stack) Session[URL_STACK];
            if (stack == null || stack.Count < 2) {
                return;
            }
            stack.Pop(); // current url
            stack.Pop(); // prev url
            // push current url back on stack.
            if (string.Compare(CurrentRequestUrl, Request.CurrentExecutionFilePath) != 0) {
                PushRequestUrl(Request.CurrentExecutionFilePath);
            }
        }

        public void ClearUserCollection() {
            Session[CURRENT_USER_COLLECTION] = null;
        }

        public static string GetParentPath(string path) {
            if (String.IsNullOrEmpty(path) || path[0] != '/')
                return null;

            int index = path.LastIndexOf('/');
            if (index < 0)
                return null;

            // parent for the root app is machine.config (null)
            if (path == "/")
                return null;

            string returnPath = path.Substring(0, index);
            if (returnPath.Length == 0 || returnPath == "/") {
               // for cassini, if returning /
               // then return null instead.
                returnPath = null;
            }

            return returnPath;
        }
       
        protected string GetQueryStringAppPath() {
            return Request.QueryString["applicationUrl"];
        }

        protected string GetQueryStringPhysicalAppPath() {
            return Request.QueryString["applicationPhysicalPath"];
        }

        public bool IsRoleManagerEnabled() {
            try {
                RoleManagerSection roleSection = null;
                Configuration config = OpenWebConfiguration(ApplicationPath);
                roleSection = (RoleManagerSection)config.GetSection("system.web/roleManager");
                return roleSection.Enabled;
            } catch {
                return false;
            }
        }

        public bool IsRuleValid(BaseValidator placeHolderValidator, RadioButton userRadio, TextBox userName, RadioButton roleRadio, DropDownList roles) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -