通过ConfirmationToken获取userId

时间:2013-06-06 16:30:34

标签: asp.net-mvc-4 simplemembership

我的应用程序正在执行电子邮件验证,向用户发送电子邮件。当用户单击链接时,将调用以下操作:

[AllowAnonymous]
    public ActionResult RegisterConfirmation(string Id) //Id=ConfirmationToken
    {
        if (WebSecurity.ConfirmAccount(Id))
        {
            //get userId and perfom some operations related to it
            return RedirectToAction("ConfirmationSuccess");
        }
        return RedirectToAction("ConfirmationFailure");
    }

我的问题是:

如何使用ConfirmationToken获取userId?

我正在使用SimpleMembershipProvider,我可以访问我的数据库上下文。

1 个答案:

答案 0 :(得分:3)

该信息位于webpages_Membership表中,您可以使用SimpleMembership的上下文通过 context.Database.SqlQuery 直接查询该信息。

select UserId from webpages_Membership where ConfirmationToken = {0}

话虽如此,我建议不要在确认完成后自动登录此人,如果这是你的意图。如comments of this article中所讨论的那样,可能会导致一些安全问题。

相关问题