您好,我正在尝试为我的公司建立一个网站,而且我试图让用户帐户工作,但每当我尝试在注册页面上注册新用户时,它都不会创建用户数据库。我通过查看SSOX localDB多次证实了这一点。该网站是用asp dotnet核心编写的。我在身份验证模板之后对此进行的唯一修改是首先使用Entity Framework代码添加用户列,并相应地将用户输入添加到表单和控制器中。我也按照https://docs.asp.net/en/latest/security/authentication/accconfirm.html上的教程进行了操作 添加帐户确认。
由于dotnetcore asp相当新,所以问的问题不多,我在谷歌和堆栈上搜索了我的问题,但未能找到问题的答案。我已将我的代码包含在下面的帐户控制器,注册视图模型和注册视图中。
如果有人知道解决方案,我会非常感激。
帐户控制器注册码:
// GET: /Account/Register
[HttpGet]
[AllowAnonymous]
public IActionResult Register(string returnUrl = null)
{
ViewData["ReturnUrl"] = returnUrl;
return View();
}
//
// POST: /Account/Register
[HttpPost]
[Authorize]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Register(RegisterViewModel model, string returnUrl = null)
{
ViewData["ReturnUrl"] = returnUrl;
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = model.UserName, Email = model.Email };
var result = await _userManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
// For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713
// Send an email with this link
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
await _emailSender.SendEmailAsync(model.UserName, model.Email, "Confirm your account", $"Please confirm your account by clicking this link: <a href='{callbackUrl}'>link</a>");
//Line commented to prevent user logging in without confirming account. //await _signInManager.SignInAsync(user, isPersistent: false);
_logger.LogInformation(3, $"User {user.Id} created a new account");
return RedirectToLocal(returnUrl);
}
AddErrors(result);
}
// If we got this far, something failed, redisplay form
return View(model);
}
这是我的RegisterViewModel代码:
using System.ComponentModel.DataAnnotations;
namespace MainSite.Models.AccountViewModels
{
public class RegisterViewModel
{
[Required]
[Display(Name = "Username")]
public string UserName { get; set; }
[Required]
[EmailAddress]
[Display(Name = "Email")]
public string Email { get; set; }
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} 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; }
}
}
我的注册视图代码:
@model RegisterViewModel
@{
ViewData["Title"] = "Register";
}
<h2>@ViewData["Title"].</h2>
<form asp-controller="Account" asp-action="Register" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal">
<h4>Create a new account.</h4>
<hr />
<div asp-validation-summary="All" class="text-danger"></div>
<div class="form-group">
<label asp-for="UserName" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="UserName" class="form-control" />
<span asp-validation-for="UserName" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<label asp-for="Email" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="Email" class="form-control" />
<span asp-validation-for="Email" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<label asp-for="Password" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="Password" class="form-control" />
<span asp-validation-for="Password" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<label asp-for="ConfirmPassword" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="ConfirmPassword" class="form-control" />
<span asp-validation-for="ConfirmPassword" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<button type="submit" class="btn btn-default">Register</button>
</div>
</div>
</form>
@section Scripts {
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
}
答案 0 :(得分:0)
您可以尝试在POST请求中取出电子邮件确认,然后离开注册,看看是否会在您的流程中产生任何差异。
此外,您可以查看ASP.NET MVC的教程 - 注册,这与您上面的内容类似。在我的应用程序中,我没有使用确认来注册用户,因为他们没有此功能,并且网站上没有该链接。
答案 1 :(得分:0)
将import UnityEngine.UI;
private var myButton:Button;
public var buttonColor : Color;
function Start () {
//myButton = GameObject.Find("MyButtonName").GetComponent(Button);
myButton = GameObject.Find("Button").GetComponent(Button);
}
function Update () {
var colorBlock = myButton.colors;
colorBlock.normalColor = new Color(0.0, 0.0, 0.0, 1.0);
colorBlock.highlightedColor = new Color(0, 1, 0.0, 1.0);
colorBlock.disabledColor = new Color(0, 0, 1, 1.0);
myButton.colors = colorBlock;
}
属性替换为[Authorize]
。