即使我检查也收到此错误,并且我的数据库中确实有此参数:
参数化查询'(@UserName nvarchar(4000))SELECT作为ASpNetUsers的电子邮件的电子邮件,期望参数'@UserName',未提供。
这在我的AccountController中:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> SendConfirmationMail() // resend confirmation link in case the users haven't received it
{
string res = null;
string connection = GetConnectionString("DefaultConnection");
using (SqlConnection myConnection = new SqlConnection(connection))
{
myConnection.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "SELECT Email AS Email FROM AspNetUsers WHERE UserName = @UserName";
cmd.Connection = myConnection;
cmd.Parameters.AddWithValue("@UserName", EConfUser);
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (reader.HasRows)
{
if (reader.Read())
{
res = reader["Email"].ToString(); // get user's email from db
var user = await UserManager.FindByEmailAsync(res); // find applicationuser user by email
//update user's email link date
UpdateEmailLinkDate(EConfUser);
// generate email conf token and send it
codeType = "EmailConfirmation";
await SendEmail("ConfirmEmail", "Account", user, res, "WelcomeEmail", "Confirm your account");
}
myConnection.Close();
}
}
}
return RedirectToAction("ConfirmationEmailSent", "Account");
}
我将不胜感激。
尝试一下: