0

使用C#如何检索用户描述和电子邮件?MVC.Net用户说明

我使用普通的ASP.Net成员来设置用户帐户。

+0

您使用ASP.Net会员? – hunter 2010-11-24 14:50:08

回答

2

您可以通过使用控制器的动作里面User财产取得认证的用户名,然后查询memebership提供检索存储在数据库中的其他用户信息:

[Authorize] 
public ActionResult Foo() 
{ 
    // fetch the connected user from the authentication cookie 
    string username = User.Identity.Name; 
    // query the datastore to retrieve additional user information 
    var userInfo = Membership.Provider.GetUser(username, false); 
    string email = userInfo.Email; 
    string comment = userInfo.Comment; 
    return View(); 
}