我想询问程序中的错误,我创建了一个寄存器和登录页面,但我对此有疑问。
这是我在UserControler中的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RegisstrationAndLogin.Models;
using System.Net.Mail;
using System.Net;
namespace RegisstrationAndLogin.Controllers
{
public class UserController : Controller
{
//registration action
[HttpGet]
public ActionResult Registration()
{
return View();
}
//Registration Post Action
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Registration([Bind(Exclude = "IsEmailVerified, ActivationCode")]User user)
{
bool Status = false;
string message = "";
// model validation
if (ModelState.IsValid)
{
var isExist = IsEmailExist(user.EmailID);
if(isExist)
{
ModelState.AddModelError("EmailExist", "Email already exist");
return View(user);
}
user.ActivationCode = Guid.NewGuid();
user.Password = Crypto.Hash(user.Password);
user.ConfirmPassword = Crypto.Hash(user.ConfirmPassword); //
user.IsEmailVerified = false;
using (MyDatabaseEntities dc = new MyDatabaseEntities())
{
dc.Users.Add(user);
dc.SaveChanges();
//Send Email To User
SendVerificationLinkEmail(user.EmailID,user.ActivationCode.ToString());
message = "Registration SuccessFully Done. Account activation link " + " has been sent to your email id: " + user.EmailID;
Status = true;
}
}
else
{
message = "Invalid Request";
}
ViewBag.Message = message;
ViewBag.Status = Status;
return View(user);
}
[NonAction]
public bool IsEmailExist(string emailID)
{
using (MyDatabaseEntities dc = new MyDatabaseEntities())
{
var v = dc.Users.Where(a => a.EmailID == emailID).FirstOrDefault();
return v != null;
}
}
[NonAction]
public void SendVerificationLinkEmail(string emailID, string activationCode)
{
var verifyUrl = "/User/VerifyAccount/" + activationCode;
var link = Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, verifyUrl);
var fromEmail = new MailAddress("soalparna@gmail.com", "Jujur Sitanggang");
var toEmail = new MailAddress(emailID);
var fromEmailPassword = "sitahuan12345"; // Replace with actual password
string subject = "Your account is successfully created!";
string body = "<br/><br/>We are excited to tell you that your wesome account is" +
" successfully created. Please click on the below link to verify your account" +
" <br/><br/><a href='" + link + "'>" + link + "</a> ";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromEmail.Address, fromEmailPassword)
};
using (var message = new MailMessage(fromEmail, toEmail)
{
Subject = subject,
Body = body,
IsBodyHtml = true
})
smtp.Send(message);
}
}
}
在模型中我有一个类user.cs这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
namespace RegisstrationAndLogin.Models
{
[MetadataType(typeof(UserMetadata))]
public partial class User
{
public string ConfirmPassword { get; set; }
}
public class UserMetadata
{
[Display(Name = "First Name")]
[Required(AllowEmptyStrings = false, ErrorMessage = "First name required")]
public string FirstName { get; set; }
[Display(Name = "Last Name")]
[Required(AllowEmptyStrings = false, ErrorMessage = "Last name required")]
public string LastName { get; set; }
[Display(Name = "Email ID")]
[Required(AllowEmptyStrings = false, ErrorMessage = "Email ID required")]
[DataType(DataType.EmailAddress)]
public string EmailID { get; set; }
[Display(Name = "Date of birth")]
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
public DateTime DateOfBirth { get; set; }
[Required(AllowEmptyStrings = false, ErrorMessage = "Password is required")]
[DataType(DataType.Password)]
[MinLength(6, ErrorMessage = "Minimum 6 characters required")]
public string Password { get; set; }
[Display(Name = "Confirm Password")]
[DataType(DataType.Password)]
[Compare("Password", ErrorMessage = "Confirm password and password do not match")]
public string ConfirmPassword { get; set; }
}
}
当我运行我的程序并单击提交注册时,我收到以下错误消息:
类型&#39; Edm.Binary&#39;成员&#39; EmailID&#39;在概念方面 键入&#39; MyDatabaseModel.User&#39;与类型不匹配 &#39; System.String&#39;成员&#39; EmailID&#39;在对象方面类型 &#39; RegisstrationAndLogin.Models.User&#39;
答案 0 :(得分:0)
$path = __DIR__.'/mysqlresults.csv';
$query = "LOAD DATA LOCAL INFILE '$path' INTO TABLE student.student_info FIELDS TERMINATED BY ','";