zoukankan      html  css  js  c++  java
  • 代码

    using System;
    using System.Collections;
    using System.Security.Cryptography;
    using System.Text;
    using System.Web;
    using System.IO;

    using System.Collections.Specialized;

    using System.Web.Caching;
    using System.Xml;
    using System.Configuration;
    using System.Xml.Serialization;


    namespace Utility
    {
     /// <summary>
     /// Common 的摘要说明。
     /// </summary>
     public class Common
     {
      #region 成员字段
      public static readonly string CacheKey = "ForumsConfiguration";
      private Hashtable providers = new Hashtable();
      private Hashtable extensions = new Hashtable();
      private static readonly Cache cache = HttpRuntime.Cache;
      private string defaultProvider;
      private string defaultLanguage;
      private string forumFilesPath;
      private bool disableBackgroundThreads = false;
      private bool disableIndexing = false;
      private bool disableEmail = false;
      private string passwordEncodingFormat = "unicode";
      private int threadIntervalEmail = 15;
      private int threadIntervalStats = 15;
      //private SystemType systemType = SystemType.Self;
      private short smtpServerConnectionLimit = -1;
      private bool enableLatestVersionCheck = true;
      private string uploadFilesPath = "/Upload/";
      private XmlDocument XmlDoc = null;
      #endregion
      public Common()
      {
       //
       // TODO: 在此处添加构造函数逻辑
       //
      }
      public enum UserPasswordFormat
      {
       ClearText = 0,
       MD5Hash = 1,
       Sha1Hash = 2,
       Encyrpted = 3
      }
      public string PasswordEncodingFormat
      {
       get { return passwordEncodingFormat; }
      }
      public static string Encrypt(UserPasswordFormat format, string cleanString, string salt)
      {
       Byte[] clearBytes;
       Byte[] hashedBytes;
       Encoding encoding = Encoding.GetEncoding("unicode");
       clearBytes = encoding.GetBytes(salt.ToLower().Trim() + cleanString.Trim());

       hashedBytes = ((HashAlgorithm) CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);

         return BitConverter.ToString(hashedBytes);
         ;                     
       
      }
      public static Common GetConfig()
      {
       Common config = cache.Get(CacheKey) as Common;
       if(config == null)
       {
        string path;
        if(HttpContext.Current != null)
         path = HttpContext.Current.Server.MapPath("~/Forums.config");
        else
         path = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "Forums.config";

        XmlDocument doc = new XmlDocument();
        doc.Load(path);
        config = new Common(doc);
        cache.Insert(CacheKey,config,new CacheDependency(path),DateTime.MaxValue,TimeSpan.Zero,CacheItemPriority.AboveNormal,null);

        //cache.ReSetFactor(config.CacheFactor);
       }
       return config;
               
      }
     }
    }

  • 相关阅读:
    每天1题算法题(4)-合并二叉树 (√)
    每天1题算法题(3)-二叉树的最大深度 (√)
    每天1题算法题(2)-二叉树的层序遍历
    每天1题算法题(1)-二叉树的中序遍历
    uni-app登录页白屏
    uni-app真机运行顶部导航栏右边按钮显示不全的问题处理
    uni-app强制横屏设置
    uni-app离线打包步骤
    银行数据仓库体系实践(18)--数据应用之信用风险建模
    银行数据仓库体系实践(17)--数据应用之营销分析
  • 原文地址:https://www.cnblogs.com/sujingnan/p/963743.html
Copyright © 2011-2022 走看看