C# 如何修复';名称';网络安全';在当前上下文中不存在';?

C# 如何修复';名称';网络安全';在当前上下文中不存在';?,c#,C#,我正在使用asp.net c#mvc和实体框架创建一个网站。在那里,我想创建重置密码部分,我有以下控制器代码 [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public ActionResult ResetPassword(ResetPasswordViewModel resetpasswordmodel) { if (ModelState.IsValid) { //User user;

我正在使用asp.net c#mvc和实体框架创建一个网站。在那里,我想创建重置密码部分,我有以下控制器代码

[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult ResetPassword(ResetPasswordViewModel resetpasswordmodel)
{
    if (ModelState.IsValid)
    {
        //User user;
        MembershipUser member;
        using (TheFoodyContext db = new TheFoodyContext())
        {
            var foundemail = (from e in db.Users
                                 where e.email == resetpasswordmodel.Email
                                 select e.email).FirstOrDefault();

            if (foundemail != null)
            {
                member = Membership.GetUser(foundemail.ToString());
            }
            else
            {
                member = null;
            }
        }

        if (member != null)
        {
            //Generate password token that will be used in the email link to authenticate user
            var token = WebSecurity.GeneratePasswordResetToken(member.Email);
            // Generate the html link sent via email
            string resetLink = "<a href='"
               + Url.Action("ResetPassword", "Account", new { rt = token }, "http")
               + "'>Reset Password Link</a>";
            // Email stuff
            string subject = "Reset your password for TheFoody.com";
            string body = "You link: " + resetLink;
            string from = "abcd123@gmail.com";
            string to = resetpasswordmodel.Email;

            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(from, to);
            message.Subject = subject;
            message.Body = body;
            SmtpClient client = new SmtpClient();

            // Attempt to send the email
            try
            {
                client.Send(message);
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", "Issue sending email: " + e.Message);
            }
        }
        else // Email not found
        {
            ModelState.AddModelError("", "No user found by that email.");
        }
    }
    return View(resetpasswordmodel);
}

我不知道如何修复此错误。

您需要将参考
WebMatrix.WebData
添加到您的项目中

之后,将using添加到类中

using WebMatrix.WebData;

看见它存在于名称空间WebMatrix.WebData中,您必须添加对WebMatrix.WebData.dll的引用。这实际上是与相同的问题。非常简单的引用缺失问题,可以手动添加,也可以安装添加它的NuGet软件包。是的,我是使用WebMatrix.WebData;添加的。但错误仍然是一样的。@Thari您是否向项目添加了引用?天哪!我真的很想念它。非常感谢。如果出现这种情况,请标记正确的答案,祝您的项目好运:)
using WebMatrix.WebData;