简体   繁体   中英

After login.aspx to default.aspx, then how do i know who just login? == Masterpage.LoginName1.UserName

After login.apsx to default.aspx, then how do i know who just login? I have a login control in masterpage, because i want to do a linq var using logined username as "Where" parameter!

on my master page:

after login.aspx to default.apsx, i have a query in the code-behind file, just want to extract the data for this specific user who justed login.

var query = from uM in db.aspnet_Memberships
                    join uD in db.UserDetails
                    on uM.UserId equals uD.UserId
                    join u in db.aspnet_Users
                    on uM.UserId equals u.UserId
                    join jL in db.JobLists
                    on uM.UserId equals jL.UserId
                    where u.UserName == Masterpage.LoginName1.UserName

                select new { jL.JobId, 
                             jL.JobTitle,
                             jL.Summary,
                             jL.Detail,
                             jL.CompanyName,
                             jL.CompanyEmail,
                             jL.PostDate,
                             uD.City, 
                             uD.State, 
                             uD.Country,
                             u.UserName,
                             jL.IsTop
                };

this gives syntax error where u.UserName == Masterpage.LoginName1.UserName thanks for advance!

User.identity.name或类似的东西。

If you are coding with asp.net you can use MembershipServices and RoleServices. And it is not goog idea to get parameter from master page. If you will use membershipservice. Later you can simply cal it's methods and get currenc logged user.

here is link to learn how to use this services

if you will use it you can simply the call User.Identity.Name and get current user name

Your loginpage can save the username to the session

   this.Session["Usename"] = ....

and your query logic retrieves it from there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM