我需要创建一个带有实体框架的注册页面,我试图使用websecurity类进行userAuth系统i编码注册这是代码
public ActionResult Register(RegisterUser model)
{
if (ModelState.IsValid)
{
// Attempt to register the user
try
{
WebSecurity.CreateUserAndAccount(model.Username, model.Password,
new { FullName = model.FullName,
Email = model.Email,
Phone = model.Phone });
WebSecurity.Login(model.Username, model.Password);
return RedirectToAction("Index", "Home");
}
catch (MembershipCreateUserException e)
{
ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
这是我的模特
public class RegisterUser{
[Required]
[Display(Name = "User Name")]
public string Username { get; set; }
[Required]
[StringLength(15, ErrorMessage = "The {0} must be at least {2} characters long and upto 15 characters", MinimumLength = 6)]
[Display(Name = "Password")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
[Display(Name="Full Name")]
public string FullName { get; set; }
[Display(Name="Email")]
public string Email { get; set; }
[Display(Name="Phone Number")]
[StringLength(12,ErrorMessage = "Wrong Phone number",MinimumLength = 9)]
public string Phone { get; set; }
}
当我运行并注册我得到的一些数据 用户代码未处理RuntimeBinderException 无法将类型'string'转换为'int'
我尝试检查我的值所有字符串和我的模型它也字符串 我不是为什么这样的程序抛出 有人可以帮帮我吗?
答案 0 :(得分:1)
我有同样的错误。就我而言,问题出在WebSecurity初始化WebSecurity.InitializeDatabaseConnection();
您必须使用userIdColumn的任何字符串字段。
userIdColumn
包含用户标识的数据库列的名称。此列必须键入整数(int)。
http://msdn.microsoft.com/en-us/library/gg569134(v=vs.111).aspx