ขอโค้ดการใช้ Session กำหนดให้เข้าหน้า Page ตามแผนกของตนเอง VB.NET , MySQL
Code (VB.NET)
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="MySql.Data.MySqlClient"%>
<%@ Page Language="VB" %>
<script runat="server">
Dim objConn As New MySqlConnection
Dim objCmd As New MySqlCommand
Dim strConnString,strSQL As String
Sub btnLogin_Click(sender As Object, e As EventArgs)
Dim objConn As New MySqlConnection
Dim objCmd As New MySqlCommand
Dim strConnString, strSQL As String
strConnString = "Server=localhost;User Id=root; Password=137964285; Database=mydatabase; Pooling=false"
objConn.ConnectionString = strConnString
objConn.Open()
Dim intNumRows As Integer
strSQL = "SELECT COUNT(*) FROM member WHERE Username = '" & Me.txtUsername.Text & "' AND Password = '" & Me.txtPassword.Text & "' "
objCmd = New MySqlCommand(strSQL, objConn)
intNumRows = objCmd.ExecuteScalar()
IF intNumRows > 0 Then
Session("strUser") = Me.txtUsername.Text
Response.Redirect("testlogin.aspx")
Else
Me.pnlLogin.Visible = False
Me.lblStatus.Visible = True
Me.lblStatus.Text = "Username/Password is wrong."
End If
objConn.Close()
objConn = Nothing
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
</script>
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
<style type="text/css">
.style1
{
height: 31px;
width: 88px;
}
.style3
{
height: 31px;
width: 208px;
}
.style5
{
height: 62px;
width: 88px;
}
.style6
{
height: 62px;
width: 208px;
}
.style7
{
height: 12px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:Label id="lblStatus" runat="server" visible="False"
style="color: #FF0000; font-weight: 700; font-size: medium; text-align: center"></asp:Label>
<table width="100" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="5"><img src="images/login/images/login_01.gif" width="804" height="136" /></td>
</tr>
<tr>
<td rowspan="3"><img src="images/login/images/login_02.gif" width="223" height="353" /></td>
<td rowspan="2"><img src="images/login/images/login_03.gif" width="20" height="299" /></td>
<td><img src="images/login/images/login_04.gif" width="333" height="75" /></td>
<td rowspan="2"><img src="images/login/images/login_05.gif" width="26" height="299" /></td>
<td rowspan="3"><img src="images/login/images/login_06.gif" width="202" height="353" /></td>
</tr>
<tr>
<td valign="top" background="images/login/images/login_07.gif">
<asp:Panel id="pnlLogin" runat="server" HorizontalAlign="Center" Width="275px">
<table border="0" style="width: 364px" align="center">
<tbody>
<tr>
<td class="style7" style="text-align: right" colspan="2">
</td>
</tr>
<tr>
<td class="style5" style="text-align: right">
<asp:Label ID="lblUsername" runat="server" text="Username"
ForeColor="White"></asp:Label>
</td>
<td class="style6">
<asp:TextBox ID="txtUsername" runat="server" Width="148px"></asp:TextBox>
<asp:RequiredFieldValidator ID="ChkUsername" runat="server"
ControlToValidate="txtUsername" ErrorMessage="*"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style1" style="text-align: right">
<asp:Label id="lblPassword" runat="server" text="Password"
ForeColor="White"></asp:Label></td>
<td class="style3">
<asp:TextBox id="txtPassword" runat="server" Width="148px"
TextMode="Password"></asp:TextBox>
</td>
</tr>
</tbody>
</table>
<br />
<asp:Button id="btnLogin" onclick="btnLogin_Click" runat="server" Text="Login"></asp:Button>
<br />
</asp:Panel>
</td>
</tr>
<tr>
<td><img src="images/login/images/login_08.gif" width="20" height="54" /></td>
<td><img src="images/login/images/login_09.gif" width="333" height="54" /></td>
<td><img src="images/login/images/login_10.gif" width="26" height="54" /></td>
</tr>
<tr>
<td colspan="5"><img src="images/login/images/login_11.gif" width="804" height="108" /></td>
</tr>
</table>
</form>
<p>
</p>
</body>
</html>
Date :
2013-11-07 11:38:11
By :
artn
Load balance : Server 04