保存登录名在asp.net当前用户身份登录名、身份、用户、net

2023-09-04 04:43:38 作者:断念

所以,我正在做一个asp.net登录。我想,人们用它来搭配一个id在我的SQL数据库的登录名。所以,我可以取回他们的信息。但是,目前,当我使用code以下,从中我得到我目前的计算机的名称。不过,我希望用户身份是他们写的东西用户名文本在登录屏幕上。

So I'm making a asp.net login. I want the login name that people use to match an id in my SQL database. So that I can retrieve their information. But currently when I use the code below, from which I get the name of the computer I am currently on. However I would like the user Identity to be what they write in the username textbox at the login screen.

If HttpContext.Current.User.Identity.IsAuthenticated Then
    Dim userName As String = HttpContext.Current.User.Identity.Name
    Response.Write(userName)
End If

所以,我看着它在网上,我认为它可能是与我的web.config文件。当我完全陌生asp.net我不知道。但这里是我的Web.config文件的一部分。

So I looked for it on net and I think it might have something to do with my web.config file. As I'm totally new to asp.net I wouldn't know. However here's a part of my Web.config file.

<authentication mode="Forms">
    <forms name=".ASPXFORMSAUTH"
        loginUrl="Login.aspx"
        protection="All"
        timeout="30"
        path="/" />
</authentication>
<authorization>
    <deny users="?" />
</authorization>

所以任何想法? :)

so any ideas? :)

推荐答案

设置使用登录名

FormsAuthentication.RedirectFromLoginPage(UserName.Text, RememberMe.Checked);

和retrive使用

User.Identity.Name

引用链接, bytes.com 和 asp.net教程