根据项目的Visual Studio 2017帐户文件夹中的注册代码中的说明,使用来自Microsoft身份验证和密码恢复的说明(C#)。
错误讯息:
System.InvalidOperationException:'找不到UserId。'
失败的地方: 在 Register.aspx.cs
中using System;
using System.Linq;
using System.Web;
using System.Web.UI;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using Owin;
using FHSF_5_DEV.Models;
:
:
:
protected void CreateUser_Click(object sender, EventArgs e)
{
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
var signInManager = Context.GetOwinContext().Get<ApplicationSignInManager>();
var user = new ApplicationUser() { UserName = UserName.Text, Email = UserEmail.Text };
IdentityResult result = manager.Create(user, Password.Text);
if (result.Succeeded)
{
string code = manager.GenerateEmailConfirmationToken(user.Id);
string callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Email, Request);
==> manager.SendEmail(user.Email, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>.");**
答案 0 :(得分:0)
使用User.Email代替User.ID.原始代码设置了身份验证代码,假设电子邮件和用户ID /用户名相同。