1

我想显示经过身份验证的用户的名字和姓氏。我知道“WebSecurity”类的“CurrentUserName”属性将检索当前经过身份验证的用户,但是如何检索其名字和姓氏?

我尝试查询用户表,但我总是收到一条关于 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>

...

4

1 回答 1

1

删除 SQL 中 FirstName、LastName 字段周围的括号:

"SELECT FirstName, LastName FROM Users WHERE LOWER(Email) = LOWER(@0)"
于 2012-06-15T08:07:52.590 回答