From first inspection with the code that you've posted, you have 9 errors, 15 warnings and 2 messages. You have mis-declared variables, malformed code and you have no DOCTYPE, html or head tags on the page. The <center></center> tags have now been depreciated, you should align your code using CSS; they also can't be nested within <p></p> or <h(x)></h(x)> tags.
Visual Studio should tell you all this and shouldn't allow you to deploy the site in this condition.
For best practice, you should use code-behind scripts with ASP.NET.
Try setting up the page like this:
Login.aspx:
HTML Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Login.aspx.vb" Inherits="_Login" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- Page Title -->
<title>Login Page</title>
<!-- Meta Block -->
<meta content="text/html; charset=iso-8859-1" http-equiv="content-type" />
<meta content="Login Page" name="description" />
<meta content="login, page" name="keywords" />
<meta content="all,index,follow" name="robots" />
<meta content="noodp" name="msnbot" />
<meta content="global" name="distribution" />
<!-- CSS Stylesheet Links -->
<link href="default.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="pagewide_form" runat="server">
<div id="page">
<form id="login" action="<%= Request.ServerVariables("SCRIPT_NAME") %>" runat="server">
<h1 class="centreText">
Company Name
</h1>
<h2 class="centreText">
Project
</h2>
<br />
<br />
<br />
<p class="centreText">
Enter Username and Password
</p>
<br />
<p class="centreText">
USER NAME
<input type="text" id="txtUser" runat="server" />
<br />
<br />
PASSWORD
<input type="password" id="txtPass" runat="server" /><br />
<br />
<input type="submit" id="btnGo" value="Login" runat="server" />
</p>
</form>
</div>
</form>
</body>
</html>
Login.aspx.vb:
PHP Code:
Option Explicit On
Option Strict On
Partial Class _Login
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Response.Expires = -1000 'Makes the browser not cache this page
Response.Buffer = True 'Buffers the content so our Response.Redirect will work
Session("UserLoggedIn") = ""
If Request.Form("txtUser") <> "" And Request.Form("txtPass") <> "" Then
CheckLogin()
End If
End Sub
Sub CheckLogin()
Dim db As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rs As New ADODB.Recordset
db.ConnectionString = "Provider=sqloledb;Data Source=datasource;Initial Catalog=catalog;User Id=user;Password=password;"
Dim sql As String = "SELECT * FROM CarInfo WHERE EmpID = '" & txtUser.Value & "'"
db.Open()
rs = db.Execute(sql)
Session("UserLoggedIn") = "false"
Do While Not rs.EOF
If Request.Form("txtUser") Is rs("EmpID") And Request.Form("txtPass") Is rs("Password") Then
Session("UserLoggedIn") = "true"
Exit Do
End If
rs.MoveNext()
Loop
db.Close()
If Session("UserLoggedIn") Is "True" Then
Response.Redirect("protectedpage.asp")
Else
Response.Write("Login Failed.<br /><br />")
End If
End Sub
End Class
default.css:
PHP Code:
*, html
{
padding: 0;
margin: 0;
}
body
{
background: #ffffff url( 'back.jpg' ) no-repeat;
}
.centreText
{
text-align: center;
margin: auto;
}
Bookmarks