我只是创建了一个强大的变量来请求会话的logon_name。我这样做的原因是因为logon_name为我提供了例如daniel.ellison,而用户名变量给了我T12345(我们公司的员工ID)。如果我将@logon_name切换为@username并将我的DB的用户名值更改为我的员工ID,则可以正常工作。当我将数据库的用户名切换回daniel.ellison并将其切换回@logon_name时失败。知道为什么会这样吗?
<%@ import namespace="System.Data" %>
<%@ import namespace="MySql.data.MySqlclient" %>
<%@ import namespace="MySql.data.MySqlclient.MySqlConnection" %>
<Script runat="server">
Sub page_load()
Dim username As String = Convert.ToString(User.Identity.Name.Substring(User.Identity.Name.IndexOf("\") + 1))
Dim logon_name As String = Request.ServerVariables("LOGON_USER")
Dim dbconn As MySqlConnection
Dim mySqlCommand As MySqlCommand
Dim counter As Integer
Dim isInGroup As Boolean
Dim strSQL As String = "SELECT COUNT(*) FROM tbl_staff WHERE username = @logon_name AND group_id = 1001;"
dbconn = New MySqlConnection("server=localhost;database=imc_directory_tool;user=Directory_Admin;port=3306;password=IMCisgreat2014;")
dbconn.Open()
mySqlCommand = New MySqlCommand(strSQL, dbconn)
mySqlCommand.Parameters.AddWithValue("@logon_name", username)
counter = mySqlCommand.ExecuteScalar()
isInGroup = counter > 0
If isInGroup = True Then
Response.Write(logon_name)
Response.Write("You are part of group_id 1001")
Else
Response.Write(logon_name)
Response.Write("You are not part of group_id 1001")
End If
dbconn.Close()
End Sub
</Script>