私が開発した Web ベースのアプリケーションにニュース ユーザーを追加するために、ASP.NET ウィザード コントロールを使用していました。すべてがうまく機能します。今、システムの管理者から、システムに追加されたことを知らせる電子メール通知を新しいユーザーに送信するという新しい要件を受け取りました。メール機能をコードに追加したところ動作しましたが、IE ブラウザで左下隅にエラー アイコンが表示され、その理由がわかりません。
Problems with the Web page might prevent it from being displayed properly or functioning properly....
Line: 74
Char: 7
Error: Object Expected
Code: 0
では、このエラーを取り除く方法は?
メール機能を使用したコード ビハインド:
protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
{
//If one of the items is selected AND a username exists in the Username session object update the user role
string username = TextBox1.Text;
if (!String.IsNullOrEmpty(radio1.SelectedValue) && !String.IsNullOrEmpty(username))
{
string connString = "Data Source=localhost;Initial Catalog=TestDB;Integrated Security=True";
string insertUserCommand = "INSERT INTO employee (Name, Username, JobTitle, BadgeNo, EmpOrgType, DivisionCode) values (@Name, @Username, @JobTitle, @BadgeNo, @EmpOrgType, @DivisionCode)";
string cmdText = "SELECT Count(*) FROM employee WHERE Username = '" + username + "'";
using (SqlConnection conn = new SqlConnection(connString))
{
conn.Open();
// Open DB connection.
using (SqlCommand cmd = new SqlCommand(cmdText, conn))
{
if ((int)cmd.ExecuteScalar() == 0){
.........................................
}
}
}
//For updating the role of the user
string deleteCommand = "DELETE FROM UserRole where Username=@Username";
string insertCommand = "INSERT INTO UserRole (RoleID,Username) values(@RoleID,@Username)";
using (SqlConnection conn = new SqlConnection(connString))
{
conn.Open();
//using (SqlCommand cmd = new SqlCommand(cmdText, conn))
using (SqlCommand cmd = new SqlCommand(deleteCommand, conn))
{
cmd.Parameters.AddWithValue("@Username", username);
cmd.ExecuteNonQuery();
//Now the insert
cmd.CommandText = insertCommand;
cmd.Parameters.Clear(); //need this because still has params from del comm
cmd.Parameters.AddWithValue("@RoleID", radio1.SelectedValue);
cmd.Parameters.AddWithValue("@Username", username);
cmd.ExecuteNonQuery();
//infoSpan.InnerText = String.Format("The users role has been updated to - {0}", radio1.SelectedValue);
//cmd.ExecuteScalar();
//infoSpan.InnerText = String.Format("The users role has been updated to - {0}", radio1.SelectedValue);
}
}
Wizard1.Visible = false;
wizard.InnerHtml = "...............";
}
Send(username);
}
/*****************************************************/
/*For sending an email */
protected void Send(string toAddresses, string fromAddress, string MailSubject, string MessageBody, bool isBodyHtml)
{
SmtpClient sc = new SmtpClient("MailAddress");
try
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress("test@mailAddress.com", "Test Sys.");
msg.Bcc.Add(toAddresses);
msg.Subject = MailSubject;
msg.Body = MessageBody;
msg.IsBodyHtml = isBodyHtml;
sc.Send(msg);
}
catch (Exception ex)
{
throw ex;
}
}
protected void SendEmailToUser(string username)
{
string connString = "Data Source=localhost;Initial Catalog=TestDB;Integrated Security=True";
string networkID = username.ToString();
using (SqlConnection conn = new SqlConnection(connString))
{
var sbEmailAddresses = new System.Text.StringBuilder(2000);
//initiate the varibles that will be retreived from the database
string name = null;
// Open DB connection.
conn.Open();
string cmdText2 = @"SELECT Name
FROM dbo.employee
WHERE (Username = @networkID)";
using (SqlCommand cmd = new SqlCommand(cmdText2, conn))
{
cmd.Parameters.AddWithValue("@networkID", networkID);
SqlDataReader reader = cmd.ExecuteReader();
if (reader != null)
{
if (reader.Read())
{
name = reader["Name"].ToString();
sbEmailAddresses.Append(username).Append("@mailAddress.com");
}
}
//var sEMailAddresses = sbEmailAddresses.ToString();
string body = "..........................";
Send(sbEmailAddresses.ToString(), "", "Welcome", body, true);
sbEmailAddresses.Clear();
}
conn.Close();
}
}