ASP.NET 具有标识的 WebForms
ASP.NET WebForms with Identity
我创建了一个 Web Forms 4.5.2 测试应用程序。这是一个由两部分组成的问题。
(1) 我看到 Microsoft.AspNet.Identity.Core 已安装。此版本与 Web 表单兼容还是仅与 ASP.NET 核心应用程序兼容?
(2) 在尝试使重置密码表单正常工作时,我收到了一条无用的一般错误消息,因此我调试了以下开箱即用的代码:
protected void Reset_Click(object sender, EventArgs e)
{
string code = IdentityHelper.GetCodeFromRequest(Request);
if (code != null)
{
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
var user = manager.FindByName(Email.Text);
if (user == null)
{
ErrorMessage.Text = "No user found";
return;
}
var result = manager.ResetPassword(user.Id, code, Password.Text);
if (result.Succeeded)
{
Response.Redirect("~/Account/ResetPasswordConfirmation");
return;
}
ErrorMessage.Text = result.Errors.FirstOrDefault();
return;
}
ErrorMessage.Text = "An error has occurred";
return;
}
}
IdentityHelper.GetCodeFromRequest(请求)返回空值。在 IdentityModels.cs class 我看到以下内容:
public const string CodeKey = "code";
public static string GetCodeFromRequest(HttpRequest request)
{
return request.QueryString[CodeKey];
}
我本以为这会开箱即用?由于没有生成查询参数,我是否假设我们应该自己编写代码?这里甚至需要 CodeKey 查询参数,还是有其他方法来获取 ResetPassword 方法所需的令牌?
是的,它兼容。
"code"生成于Forgot.aspx.cs:
string code = manager.GeneratePasswordResetToken(user.Id);
//(out of the box its commented out)
并通过电子邮件发送,没有密码,每个人都可以重置。
我创建了一个 Web Forms 4.5.2 测试应用程序。这是一个由两部分组成的问题。
(1) 我看到 Microsoft.AspNet.Identity.Core 已安装。此版本与 Web 表单兼容还是仅与 ASP.NET 核心应用程序兼容?
(2) 在尝试使重置密码表单正常工作时,我收到了一条无用的一般错误消息,因此我调试了以下开箱即用的代码:
protected void Reset_Click(object sender, EventArgs e)
{
string code = IdentityHelper.GetCodeFromRequest(Request);
if (code != null)
{
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
var user = manager.FindByName(Email.Text);
if (user == null)
{
ErrorMessage.Text = "No user found";
return;
}
var result = manager.ResetPassword(user.Id, code, Password.Text);
if (result.Succeeded)
{
Response.Redirect("~/Account/ResetPasswordConfirmation");
return;
}
ErrorMessage.Text = result.Errors.FirstOrDefault();
return;
}
ErrorMessage.Text = "An error has occurred";
return;
}
}
IdentityHelper.GetCodeFromRequest(请求)返回空值。在 IdentityModels.cs class 我看到以下内容:
public const string CodeKey = "code";
public static string GetCodeFromRequest(HttpRequest request)
{
return request.QueryString[CodeKey];
}
我本以为这会开箱即用?由于没有生成查询参数,我是否假设我们应该自己编写代码?这里甚至需要 CodeKey 查询参数,还是有其他方法来获取 ResetPassword 方法所需的令牌?
是的,它兼容。
"code"生成于Forgot.aspx.cs:
string code = manager.GeneratePasswordResetToken(user.Id); //(out of the box its commented out)
并通过电子邮件发送,没有密码,每个人都可以重置。