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(); 
}