这应该不是User.Identity.Name造成的,你可以实际用两个用户调试一下,看看各自的User.Identity.Name是不是有错误。建议如果还是维持表单验证登陆,然后注册该用户的session信息。当添加部门的时候使用该Session.
解决方案 »
- 点击提交怎样设置鼠标等待?
- 求多个手机号码(半角)+逗号(半角) 正则表达式
- 帮助新手成长 感兴趣的可以了解一下
- 急得要人命!怎样让网页自动去适应不同显示器的分辨率电脑啊?
- 公司有一台服务器,目前支持JSP和ASP,我如果再加个支持ASP.NET的环境,应该如何配置?
- 动态的改变一个按钮的onclick事件???
- 这个错误怎么解决呀???
- asp.net的连操作,帮忙看一下
- aspnet_wp问题(进来就给分,解决者追加200分)
- 调查一下,有多少人在用水晶报表啊,以及关于水晶报表限制的问题
- 一个TextBox我想让它上面只能输入0~6的数字和 ,号。我应该怎么做啊?谢谢:)
- 试图运行项目时出错 ,不能调试 ,是什么原因
This section presents the code that is placed in the code-behind page (Logon.aspx.vb).
Open the Logon.aspx.vb file.
Import the required namespaces in the code-behind file:Imports System.Data.SqlClient
Imports System.Web.Security
Create a ValidateUser function to validate the user credentials by looking in the database. (Make sure that you change the Connection string to point to your database.)Private Function ValidateUser(ByVal userName As String, ByVal passWord As String) As Boolean
Dim conn As SqlConnection
Dim cmd As SqlCommand
Dim lookupPassword As String lookupPassword = Nothing ' Check for an invalid userName.
' userName must not be set to nothing and must be between one and 15 characters.
If ((userName Is Nothing)) Then
System.Diagnostics.Trace.WriteLine("[ValidateUser] Input validation of userName failed.")
Return False
End If
If ((userName.Length = 0) Or (userName.Length > 15)) Then
System.Diagnostics.Trace.WriteLine("[ValidateUser] Input validation of userName failed.")
Return False
End If ' Check for invalid passWord.
' passWord must not be set to nothing and must be between one and 25 characters.
If (passWord Is Nothing) Then
System.Diagnostics.Trace.WriteLine("[ValidateUser] Input validation of passWord failed.")
Return False
End If
If ((passWord.Length = 0) Or (passWord.Length > 25)) Then
System.Diagnostics.Trace.WriteLine("[ValidateUser] Input validation of passWord failed.")
Return False
End If Try
' Consult with your SQL Server administrator for an appropriate connection
' string to use to connect to your local SQL Server.
conn = New SqlConnection("server=localhost;Integrated Security=SSPI;database=pubs")
conn.Open() ' Create SqlCommand to select pwd field from the users table given a supplied userName.
cmd = New SqlCommand("Select pwd from users where uname=@userName", conn)
cmd.Parameters.Add("@userName", SqlDbType.VarChar, 25)
cmd.Parameters("@userName").Value = userName
' Execute command and fetch pwd field into lookupPassword string.
lookupPassword = cmd.ExecuteScalar() ' Cleanup command and connection objects.
cmd.Dispose()
conn.Dispose()
Catch ex As Exception
' Add error handling here for debugging.
' This error message should not be sent back to the caller.
System.Diagnostics.Trace.WriteLine("[ValidateUser] Exception " & ex.Message)
End Try ' If no password found, return false.
If (lookupPassword Is Nothing) Then
' You could write failed login attempts here to the event log for additional security.
Return False
End If ' Compare lookupPassword and input passWord by using a case-sensitive comparison.
Return (String.Compare(lookupPassword, passWord, False) = 0)End Function
Handles cmdLogin.ServerClick
If ValidateUser(txtUserName.Value,txtUserPass.value) Then
FormsAuthentication.RedirectFromLoginPage(txtUserName.Value, _
chkPersistCookie.Checked)
Else
Response.Redirect("logon.aspx", True)
End If
End Sub
完全限定对当前活动的请求/响应上下文以及要使用的 System.Web 中的类的引用
根据当前的HttpContext得到用户的名称,所以应该不会是它造成的问题