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

📄 globals.cs

📁 本系统是在asp版《在线文件管理器》的基础上设计制作
💻 CS
📖 第 1 页 / 共 2 页
字号:
            try {
                if (CSConfiguration.GetConfig().FilesPath == "/")
                    return ApplicationPath + "/Themes/" + CSContext.Current.User.Theme;
                else
                    return ApplicationPath + CSConfiguration.GetConfig().FilesPath + "/Themes/" + CSContext.Current.User.Theme;
            } catch {
                return "";
            }
        }

        static public string ApplicationPath {

            get {
                string applicationPath = "/";
				
				if(HttpContext.Current != null)
					applicationPath = HttpContext.Current.Request.ApplicationPath;

                // Are we in an application?
                //
                if (applicationPath == "/") {
                    return string.Empty;
                } else {
                    return applicationPath;
                }
            }

        }

        /// <summary>
        /// Name of the skin to be applied
        /// </summary>
        static public String Skin {
            get {
                return "default";
            }
        }

        static public SiteUrls GetSiteUrls() 
        {
            return SiteUrls.Instance();
        }

        #endregion

        #region Language
        static public string Language 
        {
            get {
				return CSConfiguration.GetConfig().DefaultLanguage;
            }
        }
        #endregion

      
		/// <summary>
		/// 获取IP地址
		/// </summary>
		static public string IPAddress
		{
			get 
			{
				string ipAddress = "000.000.000.000";
				try
				{
					// 有可能是后台调用
					HttpContext context = HttpContext.Current;				
					ipAddress = GetUserIpAddress(context);
				}
				catch{}
				return ipAddress;
			}
		}

		/// <summary>
		/// 透过代理获取真实IP
		/// </summary>
		/// <param name="context"></param>
		/// <returns></returns>
		public static string GetUserIpAddress(HttpContext context)
		{
			string result = String.Empty;
			if (context == null) 
				return result;

			// 透过代理取真实IP
			result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
			if (null == result || result == String.Empty)
				result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
			
			if (null == result || result == String.Empty)
				result = HttpContext.Current.Request.UserHostAddress;

			return result;
		}


        #region CreateTemporaryPassword Replaced by WSHA
        /// <summary>
        /// Creates a temporary password of a specified length.
        /// </summary>
        /// <param name="length">The maximum length of the temporary password to create.</param>
        /// <returns>A temporary password less than or equal to the length specified.</returns>
//        public static String CreateTemporaryPassword(int length) 
//        {
//
//            string strTempPassword = Guid.NewGuid().ToString("N");
//
//            for(int i = 0; i < (length / 32); i++) {
//                strTempPassword += Guid.NewGuid().ToString("N");
//            }
//
//            return strTempPassword.Substring(0, length);
//        }
        #endregion

        public static int SafeInt(string text, int defaultValue)
        {
            if(!IsNullorEmpty(text))
            {
                try
                {
                    return Int32.Parse(text);
                }
                catch(Exception){}
                
            }

            return defaultValue;
        }

        public static bool IsNullorEmpty(string text)
        {
            return text == null || text.Trim() == string.Empty;
        }

        public static string HostPath(Uri uri)
        {
            string portInfo = uri.Port == 80 ? string.Empty : ":" + uri.Port.ToString();
            return string.Format("{0}://{1}{2}",uri.Scheme,uri.Host, portInfo);
        }

        public static string FullPath(string local)
        {
            return FullPath(HostPath(HttpContext.Current.Request.Url),local);
        }

        public static string FullPath(string hostPath, string local)
        {
            return hostPath + local;
        }

		public static bool ValidateApplicationKey(string appKey, out string formattedKey)
		{
            
			formattedKey = appKey.Trim().Replace(" ", "_").ToLower();

			//Should we remove these items? Or just encode them. We can change this logic 
			string[] parts = formattedKey.Split('!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '[', ']', '{', '}', '<', '>', ',', '?', '\\', '/', '\'','+','=','~','`','|');
			formattedKey =  string.Join("", parts);
			formattedKey = Globals.UrlEncode(formattedKey);

            return formattedKey == appKey;
		}

		/// <summary>
		/// 获取属性值
		/// </summary>
		/// <param name="headerValue"></param>
		/// <param name="attrName"></param>
		/// <returns></returns>
		public static string GetAttributeFromHeader(string headerValue, string attrName)
		{
			int attrLen;
			if (headerValue == null)
			{
				return null;
			}
			int len = headerValue.Length;
			int attrNameLen = attrName.Length;
			int index = 1;
			while (index < len)
			{
				index = CultureInfo.InvariantCulture.CompareInfo.IndexOf(headerValue, attrName, index, CompareOptions.IgnoreCase);
				if ((index < 0) || ((index + attrNameLen) >= len))
				{
					break;
				}
				char start = headerValue[index - 1];
				char end = headerValue[index + attrNameLen];
				if ((((start == ';') || (start == ',')) || char.IsWhiteSpace(start)) && ((end == '=') || char.IsWhiteSpace(end)))
				{
					break;
				}
				index += attrNameLen;
			}
			if ((index < 0) || (index >= len))
			{
				return null;
			}
			index += attrNameLen;
			while ((index < len) && char.IsWhiteSpace(headerValue[index]))
			{
				index++;
			}
			if ((index >= len) || (headerValue[index] != '='))
			{
				return null;
			}
			index++;
			while ((index < len) && char.IsWhiteSpace(headerValue[index]))
			{
				index++;
			}
			if (index >= len)
			{
				return null;
			}
			if ((index < len) && (headerValue[index] == '"'))
			{
				if (index == (len - 1))
				{
					return null;
				}
				attrLen = headerValue.IndexOf('"', (int) (index + 1));
				if ((attrLen < 0) || (attrLen == (index + 1)))
				{
					return null;
				}
				return headerValue.Substring(index + 1, (attrLen - index) - 1).Trim();
			}
			attrLen = index;
			while (attrLen < len)
			{
				if ((headerValue[attrLen] == ' ') || (headerValue[attrLen] == ',') || (headerValue[attrLen] == ';'))
				{
					break;
				}
				attrLen++;
			}
			if (attrLen == index)
			{
				return null;
			}
			return headerValue.Substring(index, attrLen - index).Trim();
		}

    }
}

⌨️ 快捷键说明

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