我想显示经过身份验证的用户的名字和姓氏。 我知道“WebSecurity”类的“CurrentUserName”属性将检索当前经过身份验证的用户,但是如何检索其姓氏和名字呢?
我尝试查询users表但是我总是有关于SQL查询行的错误消息(启动var UserData ...):','附近的语法不正确
在代码部分:
@{
// Initialize general page variables
var authenticatedUser = "";
var authenticatedUserFirstName = "";
var authenticatedUserLastName = "";
if (WebSecurity.IsAuthenticated) {
authenticatedUser = WebSecurity.CurrentUserName;
var db = Database.Open("MyDatabase");
var UserData = db.QuerySingle("SELECT (FirstName, LastName) FROM Users WHERE LOWER(Email) = LOWER(@0)", authenticatedUser);
authenticatedUserFirstName = UserData.FirstName;
authenticatedUserLastName = UserData.LastName;
}
}
在标记部分:
@if (WebSecurity.IsAuthenticated) {
<p>
Hello, <a class="username" href="~/Account/ChangePassword" title="Change password">@authenticatedUserFirstName @authenticatedUserLastName</a>!
<a href="~/Account/Logout">Logout</a>
</p>
...
答案 0 :(得分:1)
从SQL中的FirstName,LastName字段周围删除括号:
"SELECT FirstName, LastName FROM Users WHERE LOWER(Email) = LOWER(@0)"