if (e.Row.RowType == DataControlRowType.DataRow)
{
// Display the checkbox when the config name is password.
var tbConfigName = (TextBox) e.Row.Cells[0].Controls[1];
var tbConfigValue = (TextBox)e.Row.Cells[1].Controls[1];
var cbEncrypted = (CheckBox) e.Row.Cells[2].Controls[1];
//tbConfigName.Attributes.Add("onchange", string.Format("ValueChanged('{0}','{1}');",
//tbConfigName.UniqueID, cbEncrypted.UniqueID));
//string imgPath = this.ResolveUrl("~/images/padlock.jpg");
//cbEncrypted.Text = "<img src='" + imgPath + "' alt='' />";
//cbEncrypted.Attributes.Add("onclick", string.Format("CheckedChanged('{0}','{1}');",
// tbConfigValue.UniqueID, cbEncrypted.UniqueID));
//cbEncrypted.Style.Add("display","none");
if (tbConfigName.Text.ToLower().Equals("password"))
{
// Display the checkbox when the config name is password.
//cbEncrypted.Style.Add("display", "block");
if(ViewState["password"]!=null&&!string.IsNullOrEmpty(ViewState["password"].ToString()))
{
//Display the password in password mode if encrypted otherwise in textmode
string[] pwdArray = ViewState["password"].ToString().Split('#');
cbEncrypted.Checked = pwdArray[0].ToLower().Equals("true") ? true : false;
tbConfigValue.TextMode = pwdArray[0].ToLower().Equals("true")
? TextBoxMode.Password
: TextBoxMode.SingleLine;
tbConfigValue.Attributes.Add("value", pwdArray[0].ToLower().Equals("true")
? GetDecryptedPassword(pwdArray[1])
: pwdArray[1]);
//ViewState.Remove("password");
}
}
if (tbConfigName.Text.ToLower().Equals("host"))
{
// Display the checkbox when the config name is password.
//cbEncrypted.Style.Add("display", "block");
if (ViewState["host"] != null && !string.IsNullOrEmpty(ViewState["host"].ToString()))
{
//Display the password in password mode if encrypted otherwise in textmode
string[] pwdArray = ViewState["host"].ToString().Split('#');
cbEncrypted.Checked = pwdArray[0].ToLower().Equals("true") ? true : false;
tbConfigValue.TextMode = pwdArray[0].ToLower().Equals("true")
? TextBoxMode.Password
: TextBoxMode.SingleLine;
tbConfigValue.Attributes.Add("value", pwdArray[0].ToLower().Equals("true")
? GetDecryptedPassword(pwdArray[1])
: pwdArray[1]);
//ViewState.Remove("host");
}
}
if (tbConfigName.Text.ToLower().Equals("servicesurl"))
{
// Display the checkbox when the config name is password.
//cbEncrypted.Style.Add("display", "block");
if (ViewState["servicesUrl"] != null && !string.IsNullOrEmpty(ViewState["servicesUrl"].ToString()))
{
//Display the password in password mode if encrypted otherwise in textmode
string[] pwdArray = ViewState["servicesUrl"].ToString().Split('#');
cbEncrypted.Checked = pwdArray[0].ToLower().Equals("true") ? true : false;
tbConfigValue.TextMode = pwdArray[0].ToLower().Equals("true")
? TextBoxMode.Password
: TextBoxMode.SingleLine;
tbConfigValue.Attributes.Add("value", pwdArray[0].ToLower().Equals("true")
? GetDecryptedPassword(pwdArray[1])
: pwdArray[1]);
//ViewState.Remove("servicesUrl");
}
}
if (tbConfigName.Text.ToLower().Equals("pollingobject"))
{
// Display the checkbox when the config name is password.
//cbEncrypted.Style.Add("display", "block");
if (ViewState["PollingObject"] != null && !string.IsNullOrEmpty(ViewState["PollingObject"].ToString()))
{
//Display the password in password mode if encrypted otherwise in textmode
string[] pwdArray = ViewState["PollingObject"].ToString().Split('#');
cbEncrypted.Checked = pwdArray[0].ToLower().Equals("true") ? true : false;
tbConfigValue.TextMode = pwdArray[0].ToLower().Equals("true")
? TextBoxMode.Password
: TextBoxMode.SingleLine;
tbConfigValue.Attributes.Add("value", pwdArray[0].ToLower().Equals("true")
? GetDecryptedPassword(pwdArray[1])
: pwdArray[1]);
//ViewState.Remove("PollingObject");
}
}
if (tbConfigName.Text.ToLower().Equals("debug"))
{
// Display the checkbox when the config name is debug.
//cbEncrypted.Style.Add("display", "block");
if (ViewState["debug"] != null && !string.IsNullOrEmpty(ViewState["debug"].ToString()))
{
//Display the password in password mode if encrypted otherwise in textmode
string[] pwdArray = ViewState["debug"].ToString().Split('#');
cbEncrypted.Checked = pwdArray[0].ToLower().Equals("true") ? true : false;
tbConfigValue.TextMode = pwdArray[0].ToLower().Equals("true")
? TextBoxMode.Password
: TextBoxMode.SingleLine;
tbConfigValue.Attributes.Add("value", pwdArray[0].ToLower().Equals("true")
? GetDecryptedPassword(pwdArray[1])
: pwdArray[1]);
//ViewState.Remove("debug");
}
}
if (tbConfigName.Text.ToLower().Equals("version"))
{
// Display the checkbox when the config name is version.
//cbEncrypted.Style.Add("display", "block");
if (ViewState["version"] != null && !string.IsNullOrEmpty(ViewState["version"].ToString()))
{
//Display the password in password mode if encrypted otherwise in textmode
string[] pwdArray = ViewState["version"].ToString().Split('#');
cbEncrypted.Checked = pwdArray[0].ToLower().Equals("true") ? true : false;
tbConfigValue.TextMode = pwdArray[0].ToLower().Equals("true")
? TextBoxMode.Password
: TextBoxMode.SingleLine;
tbConfigValue.Attributes.Add("value", pwdArray[0].ToLower().Equals("true")
? GetDecryptedPassword(pwdArray[1])
: pwdArray[1]);
//ViewState.Remove("version");
}
}
if (tbConfigName.Text.ToLower().Equals("username"))
{
// Display the checkbox when the config name is version.
//cbEncrypted.Style.Add("display", "block");
if (ViewState["username"] != null && !string.IsNullOrEmpty(ViewState["username"].ToString()))
{
//Display the password in password mode if encrypted otherwise in textmode
string[] pwdArray = ViewState["username"].ToString().Split('#');
cbEncrypted.Checked = pwdArray[0].ToLower().Equals("true") ? true : false;
tbConfigValue.TextMode = pwdArray[0].ToLower().Equals("true")
? TextBoxMode.Password
: TextBoxMode.SingleLine;
tbConfigValue.Attributes.Add("value", pwdArray[0].ToLower().Equals("true")
? GetDecryptedPassword(pwdArray[1])
: pwdArray[1]);
//ViewState.Remove("username");
}
}
加密方法
private static string GetDecryptedPassword(string encryptedPassword)
{
var passwordBuilder = new PasswordBuilder(new MD5Encryption());
return passwordBuilder.GetDecryptedPassword(encryptedPassword, new FileCertificateProvider());
}