saving the login name as current user identity in asp.net

时间秒杀一切 提交于 2019-12-23 03:35:09

问题


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

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? :)


回答1:


set login name using

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

and retrive using

User.Identity.Name

reference links, bytes.com and asp.net tutorial




回答2:


Use the ViewStates to maintain the Login state of the user.



来源:https://stackoverflow.com/questions/5152735/saving-the-login-name-as-current-user-identity-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!