lap*_*sus 5 c# asp.net-mvc asp.net-identity-2
我在标准的ASP.NET MVC项目中向ASP.NET身份模型添加了电子邮件验证.以下行导致AccessViolationException:
callbackUrl = Url.Action("ConfirmEmail", "Account", confirmModel, Request.Url.Scheme);
Run Code Online (Sandbox Code Playgroud)
更新: 由于问题无法解释,它就消失了.我会试着弄清楚是什么让它消失了.令我担心的是,我不知道解决方案有任何重大变化.
用于注册用户的完整帐户控制器方法如下所示:
// POST: /Account/Register
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
ApplicationUser user = new ApplicationUser { UserName = model.Email, Email = model.Email };
IdentityResult result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
string callbackUrl;
try
{
string requestScheme = Request.Url.Scheme;
object confirmModel = new { userId = user.Id, code = code };
callbackUrl = Url.Action("ConfirmEmail", "Account", confirmModel, Request.Url.Scheme); // TODO: Fails somehow!
}
catch (Exception ex)
{
Debug.WriteLine(ex);
callbackUrl = "https://localhost:43000/Account/ConfirmEmail?userid=" + user.Id + "&code=" + code;
}
await
UserManager.SendEmailAsync(
userId: user.Id,
subject: "Verify it's you",
body: "Please confirm your email address by clicking <a href=\"" + callbackUrl + "\">here</a>");
return View("CheckYourEmail");
}
AddErrors(result);
}
// If we got this far, something failed, redisplay form
return View(model);
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,没有内部异常或任何有用的东西.
catch()块作为一种解决方法解决了这个问题.
但我真的很好奇这里出了什么问题.