Asp.net mvc 4 登录激活用户MVC4
我的web应用程序包括一封确认电子邮件,用于确认用户(通过电子邮件)。 这件事的工作,电子邮件得到发送与确认令牌,用户可以点击链接,用户得到确认 如何让激活的用户直接(自动)登录?差不多Asp.net mvc 4 登录激活用户MVC4,asp.net-mvc-4,Asp.net Mvc 4,我的web应用程序包括一封确认电子邮件,用于确认用户(通过电子邮件)。 这件事的工作,电子邮件得到发送与确认令牌,用户可以点击链接,用户得到确认 如何让激活的用户直接(自动)登录?差不多 WebSecurity.ConfirmAccount(token); WebSecurity.LogIn(??confirmeduser??); 我怎样才能得到这份确认书 (注意:我使用的是默认的MVC4成员资格提供程序)您必须拥有一个与您的令牌和用户相关的数据库。看看这个: 这是从那篇文章中摘取的代码: [
WebSecurity.ConfirmAccount(token);
WebSecurity.LogIn(??confirmeduser??);
我怎样才能得到这份确认书
(注意:我使用的是默认的MVC4成员资格提供程序)您必须拥有一个与您的令牌和用户相关的数据库。看看这个: 这是从那篇文章中摘取的代码:
[AllowAnonymous]
public ActionResult RegisterConfirmation(string Id)
{
if (WebSecurity.ConfirmAccount(Id))
{
using (var db = new UsersContext())
{
// Use ConfirmationToken to figure out UserId, then use that to get UserName.
int userId = db.Memberships.Single(m => m.ConfirmationToken == Id).UserId;
string userName = db.UserProfiles.Single(u => u.UserId == userId).UserName;
// Authenticate user.
FormsAuthentication.SetAuthCookie(userName, true);
}
return RedirectToAction("Index", "Home");
}
return View("ConfirmationFailure");
}
您必须有一个与您的令牌和用户具有关系的数据库。看看这个: 这是从那篇文章中摘取的代码:
[AllowAnonymous]
public ActionResult RegisterConfirmation(string Id)
{
if (WebSecurity.ConfirmAccount(Id))
{
using (var db = new UsersContext())
{
// Use ConfirmationToken to figure out UserId, then use that to get UserName.
int userId = db.Memberships.Single(m => m.ConfirmationToken == Id).UserId;
string userName = db.UserProfiles.Single(u => u.UserId == userId).UserName;
// Authenticate user.
FormsAuthentication.SetAuthCookie(userName, true);
}
return RedirectToAction("Index", "Home");
}
return View("ConfirmationFailure");
}
您必须有一个与您的令牌和用户具有关系的数据库。看看这个: 这是从那篇文章中摘取的代码:
[AllowAnonymous]
public ActionResult RegisterConfirmation(string Id)
{
if (WebSecurity.ConfirmAccount(Id))
{
using (var db = new UsersContext())
{
// Use ConfirmationToken to figure out UserId, then use that to get UserName.
int userId = db.Memberships.Single(m => m.ConfirmationToken == Id).UserId;
string userName = db.UserProfiles.Single(u => u.UserId == userId).UserName;
// Authenticate user.
FormsAuthentication.SetAuthCookie(userName, true);
}
return RedirectToAction("Index", "Home");
}
return View("ConfirmationFailure");
}
您必须有一个与您的令牌和用户具有关系的数据库。看看这个: 这是从那篇文章中摘取的代码:
[AllowAnonymous]
public ActionResult RegisterConfirmation(string Id)
{
if (WebSecurity.ConfirmAccount(Id))
{
using (var db = new UsersContext())
{
// Use ConfirmationToken to figure out UserId, then use that to get UserName.
int userId = db.Memberships.Single(m => m.ConfirmationToken == Id).UserId;
string userName = db.UserProfiles.Single(u => u.UserId == userId).UserName;
// Authenticate user.
FormsAuthentication.SetAuthCookie(userName, true);
}
return RedirectToAction("Index", "Home");
}
return View("ConfirmationFailure");
}
您的身份验证机制是“基于声明的身份验证”吗?可能本文可以帮助您刺探第9段代码中的“authManager.Authenticate(string.Empty,claimsPrincipal);”。您的身份验证机制是“基于声明的身份验证”吗?可能本文可以帮助您刺探“authManager.Authenticate”(string.Empty,claimsPrincipal);“在第9个代码段中。您的身份验证机制是“基于声明的身份验证”吗?可能本文可以帮助您窥探第9个代码段中的“authManager.Authenticate(string.Empty,claimsPrincipal);”您的身份验证机制是“基于声明的身份验证”吗?可能本文可以帮助您窥探authManager.Authenticate(string.Empty,claimsPrincipal);"在第9段代码中。Voodoo我试图应用这段代码,但我记得我无权访问成员身份,因为它们不存在于de Db上下文中。我如何访问这些成员身份?Voodoo我试图应用这段代码,但我记得我无权访问成员身份,因为它们不存在于de Db中上下文我有。我如何访问这些成员资格?巫毒我试图应用这段代码,但我记得我没有权限访问这些成员资格,因为它们不存在于de DbContext中。我如何访问这些成员资格?巫毒我试图应用这段代码,但我记得我没有权限访问这些成员资格因为它们不存在于我拥有的de DbContext中。我如何访问这些成员资格??