public partial class _Default : System.Web.UI.Page { public bool IsMd5 { get { //添加命名空间 using System.Configuration; return ConfigurationManager.AppSettings["Md5"] == "1"; } } protected void Page_Load(object sender, EventArgs e) { if (IsMd5) { //添加命名空间 using System.Web.Security; string MD5 = FormsAuthentication.HashPasswordForStoringInConfigFile("被加密的字段", "MD5"); // SHA1 MD5 } } }---------------------web.config---------------------------------- <appSettings> <!--加密, 1:代表是; 0:代表不是--> <add key="Md5" value="1"/> </appSettings>
publicpartialclass_Default:System.Web.UI.Page{publicboolIsMd5{get{//添加命名空间usingSystem.Configuration;returnConfigurationManager.AppSettings["Md5"]=="1";}}protectedvoidPage_Load(objectsender,EventArgse){if(IsMd5){//添加命名空间usingSystem.Web.Security;stringMD5=FormsAuthentication.HashPasswordForStoringInConfigFile("被加密的字段","MD5");//SHA1MD5}}}---------------------web.config----------------------------------<appSettings><!--加密,1:代表是;0:代表不是--><addkey="Md5"value="1"/></appSettings>