asp.net-mvc-4 – SimpleMembership – 向UserProfile添加电子邮件 – Syst
发布时间:2020-05-24 11:09:51 所属栏目:asp.Net 来源:互联网
导读:我很确定我已经遵循了所有步骤,但似乎错过了一些东西.在MVC4应用程序中使用simplemembership.将Email添加到UserProfile表以及Register和UserProfile模型中,将其添加到Register方法,但仍然收到错误.这是一些代码: 楷模: public class UserProfile{ public in
|
我很确定我已经遵循了所有步骤,但似乎错过了一些东西.在MVC4应用程序中使用simplemembership.将Email添加到UserProfile表以及Register和UserProfile模型中,将其添加到Register方法,但仍然收到错误.这是一些代码: 楷模: public class UserProfile
{
public int UserId { get; set; }
public string UserName { get; set; }
public string Email { get; set; }
}
public class RegisterModel
{
[Display(Name = "Email Address")]
[StringLength(20)]
// [Required]
public string Email { get; set; }
[Display(Name = "Date of Birth")]
// [Required]
public DateTime DOB { get; set; }
[Required]
[System.Web.Mvc.Remote("VerifyUserExists","Account",ErrorMessage="That Username is already taken.")]
[Display(Name = "User name")]
public string UserName { get; set; }
[Required]
[StringLength(100,ErrorMessage = "The {0} must be at least {2} characters long.",MinimumLength = 6)]
[DataType(DataType.Password)]
[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; }
}
控制器: public ActionResult Register(RegisterModel model)
{
if (ModelState.IsValid)
{
// Attempt to register the user
try
{
WebSecurity.CreateUserAndAccount(model.UserName,model.Password,new { Email = model.Email });
WebSecurity.Login(model.UserName,model.Password);
return RedirectToAction("Index","Home");
}
catch (MembershipCreateUserException e)
{
ModelState.AddModelError("",ErrorCodeToString(e.StatusCode));
}
}
我不是试图使用电子邮件地址作为登录,只是想在注册步骤中抓取它,以便我可以发送自动确认电子邮件. 我已经尝试使用EF模型中包含的UserProfile表,并且使用它,没有区别.我已经确认DB中的表有一个Email列. 解决方法如果您使用的是默认连接,请点击查看 – >打开数据库.然后,Server Explorer将展开DefaultConnection.在Tables下,您将看到UserProfile表.首先将列添加到表中并更新数据库,然后将额外的字段添加到类中.(编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 是否可以从HttpContext访问TempData键/值?
- ASP.NET – DataSourceID和DataSource有什么区别?
- asp.net-mvc – MVC .NET模型即时绑定到数组
- asp.net – Chrome在成功的文件下载(200状态)上显示“已取消
- asp.net-mvc-3 – 为什么ValidationSummary(true)显示属性错
- asp.net – 没有回发的日历控件
- asp.net core webapi 服务端配置跨域的实例
- asp.net – 当onclientclick为false时,停止onclick触发?
- asp.net-mvc-3 – Html.Action – 获取与发布
- asp.net-mvc – ASP.Net MVC风格包不包括大多数文件
推荐文章
站长推荐
- asp.net-web-api – 如何自定义认证我自己的表在
- asp.net – 存储库是否应该调用另一个存储库?或
- asp.net-mvc – 为什么需要为Html.Action定义的路
- asp.net-mvc – 将javascript对象作为字典传输到
- asp.net-mvc – Elmah.MVC对Elmah.contrib.Mvc
- asp.net – HttpError iis config在添加默认路径
- 自定义ASP.NET容器控件
- asp.net – 如何在Linux服务器上安装mono?
- asp.net – IE7和8随机挂起CSS图像
- asp.net – 哪个会员提供程序实现存储在web.conf
热点阅读
