身份电子邮件与破折号在Asp.Net身份
发布时间:2020-05-24 06:05:53 所属栏目:asp.Net 来源:互联网
导读:我正在使用ASP.NET MVC身份,当我添加一个电子邮件形式test-name@testing.com我得到验证错误消息 User name test-name@testing.com is invalid, can only contain letters or digits. 如何更改验证,以便允许接受电子邮件? 我的cshtml是: @using (Html.BeginF
|
我正在使用ASP.NET MVC身份,当我添加一个电子邮件形式test-name@testing.com我得到验证错误消息
如何更改验证,以便允许接受电子邮件? 我的cshtml是: @using (Html.BeginForm("Login","Account",new { ReturnUrl = ViewBag.ReturnUrl },FormMethod.Post,new { role = "form" }))
{
@Html.AntiForgeryToken()
<div class="reg-header">
<h2>Register</h2>
</div>
<fieldset>
@if (ViewBag.IsRegister)
{
@Html.ValidationSummary(true,"",new { @class = "text-danger" })
}
<div class="margin-bottom-20">
@Html.LabelFor(m => m.RegisterViewModel.FirstName)<br />
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
@Html.TextBoxFor(m => m.RegisterViewModel.FirstName,new { @class = "form-control" })
</div>
@Html.ValidationMessageFor(m => m.RegisterViewModel.FirstName,new { @class = "text-danger" })
</div>
<div class="margin-bottom-20">
@Html.LabelFor(m => m.RegisterViewModel.LastName)<br />
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
@Html.TextBoxFor(m => m.RegisterViewModel.LastName,new { @class = "form-control" })
</div>
@Html.ValidationMessageFor(m => m.RegisterViewModel.LastName,new { @class = "text-danger" })
</div>
<div class="margin-bottom-20">
@Html.LabelFor(m => m.RegisterViewModel.Email)<br />
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
@Html.TextBoxFor(m => m.RegisterViewModel.Email,new { @class = "form-control" })
</div>
@Html.ValidationMessageFor(m => m.RegisterViewModel.Email,new { @class = "text-danger" })
</div>
<div class="margin-bottom-20">
@Html.LabelFor(m => m.RegisterViewModel.Password)<br />
<div class="input-group ">
<span class="input-group-addon"><i class="fa fa-lock"></i></span>
@Html.PasswordFor(m => m.RegisterViewModel.Password,new { @class = "form-control" })
</div>
@Html.ValidationMessageFor(m => m.RegisterViewModel.Password,new { @class = "text-danger" })
</div>
<div class="margin-bottom-20">
@Html.LabelFor(m => m.RegisterViewModel.ConfirmPassword)<br />
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-lock"></i></span>
@Html.PasswordFor(m => m.RegisterViewModel.ConfirmPassword,new { @class = "form-control" })
<div class="clear"></div>
</div>
@Html.ValidationMessageFor(m => m.RegisterViewModel.ConfirmPassword,new { @class = "text-danger" })
</div>
<div class="row">
<div class="col-md-12">
<button class="btn-u" type="submit" name="command" value="Register">Register</button>
</div>
</div>
</fieldset>
}
这是我的控制器 RegisterViewModel model = login.RegisterViewModel;
var user = new ApplicationUser() { UserName = model.Email,FirstName = model.FirstName,LastName = model.LastName,UserRole = UserRole.Rider };
IdentityResult result = await UserManager.CreateAsync(user,model.Password);
if (result.Succeeded)
{
await SignInAsync(user,isPersistent: false);
// For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
// Send an email with this link
// string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
// var callbackUrl = Url.Action("ConfirmEmail",new { userId = user.Id,code = code },protocol: Request.Url.Scheme);
// await UserManager.SendEmailAsync(user.Id,"Confirm your account","Please confirm your account by clicking <a href="" + callbackUrl + "">here</a>");
return RedirectToLocal(returnUrl);
//return RedirectToAction("Index","Home");
}
else
{
ViewBag.ReturnUrl = returnUrl;
AddErrors(result);
}
解决方法UserManager中使用的默认UserValidator具有设置为true的属性AllowOnlyAlphanumericUserNames.您将需要覆盖此值以允许特殊字符.一个可能的解决方案是用你自己的实现覆盖UserManager,如此.public class ApplicationUserManager : UserManager<ApplicationUser>
{
public ApplicationUserManager(IUserStore<ApplicationUser> store) : base(store)
{
this.UserValidator = new UserValidator<ApplicationUser>(this) { AllowOnlyAlphanumericUserNames = false };
}
}
public class ApplicationUser : IdentityUser
{
//Custom Properties etc.
} (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 是否可以使Page.IsPostBack独立于ASP.net而变为真?
- asp.net – 我应该买Obout控件吗?
- asp.net-mvc-3 – ASP.net MVC – 模型绑定不包括类字段?
- asp.net – 谁负责处理HttpPostedFile.InputStream – 何时
- “记住我”与ASP.NET MVC认证不工作
- asp.net – 为什么在调试我的Web应用程序时得到“服务器提交
- 在ASP.NET中使用Visual Studio发布功能有什么好处?
- asp.net-mvc – 如何在c#/ asp.net中使用jquery或ajax来更新
- asp.net – 一个cookie文件的最大大小是多少?
- ASP.NET MVC中的asp.net-mvc – 文件大小上传限制:web.con
推荐文章
站长推荐
- ASP.NET MVC UrlHelper.GenerateUrl异常:“无法
- asp.net-mvc – 属性级验证错误阻碍了类级验证的
- asp.net – FormsAuthentication.SetAuthCookie(
- 服务器端ASP.Net Ajax异常处理
- asp.net-mvc – 您可以使用IOC容器将依赖项注入自
- asp.net-mvc – 运行时错误没有为扩展名’.cshtm
- ASP.Net:如果我有Session ID,可以获取Session对
- asp.net-mvc-3 – 有没有办法使用@ Html.HiddenF
- Asp.net 实现Session分布式储存(Redis,Mongodb,M
- asp.net-mvc – MultiSelect jqgrid MVC3的OnCli
热点阅读
