I'm trying to display an errormessage for the user
[email protected] who is denied access in the web.config file.
Here's the code in the web.config file:
<?xml version="1.0" encoding="iso-8859-1"?>
<configuration>
<system.web>
<authentication mode="Forms">
<forms name=".WroxUnited" loginUrl="Exercises\zipcodelogin.aspx" protection="Validation" timeout="999999" />
</authentication>
<authorization>
<allow users="?" />
</authorization>
</system.web>
<location path="Exercises">
<system.web>
<authorization>
<deny users="
[email protected]" />
<deny users="?" />
</authorization>
</system.web>
</location>
</configuration>
And here's the code in the Exercises/zipcodelogin.aspx file:
<%@ Page Language="
VB" ContentType="text/html" debug="true" %>
<script runat="server">
Sub Click_Validate(Sender As Object, E As EventArgs)
Dim Zipcode As String = "123"
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\Boken\DB\WroxDBAuth.mdb"
Dim dbConnection As New System.Data.OleDb.OleDbConnection(connectionString )
Dim queryString As String = "SELECT * FROM Tbl_MA_Users " & _
"WHERE Email = @Username " & _
"AND Pwd = @Password"
Dim dbCommand As New System.Data.Oledb.OleDbCommand(queryString, dbConnection)
dbCommand.Parameters.Add("@Username", System.Data.DbType.String).Value = txtUserName.Text
dbCommand.Parameters.Add("@Password", System.Data.DbType.String).Value = txtPassword.Text
dbConnection.Open
Dim dataReader As System.Data.OleDb.OleDbDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavio r.CloseConnection)
If dataReader.Read() And txtZipCode.Text = Zipcode Then
FormsAuthentication.RedirectFromLoginPage(txtUserN ame.Text, True)
'************************************************* ************************************************** *******************************
' If the user is denied in the web.config file I'd like to create a error message here like lblMsg.Text = "You're denied access"
'************************************************* ************************************************** *******************************
Else
lblMsg.Text = "Invalid Credentials: Please try again<br />"
End If
dataReader.Close()
End Sub
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form runat="server">
Username: <asp:TextBox id="txtUserName" runat="server" />
<br />
Password: <asp:TextBox id="txtPassword" textmode="Password" runat="server" />
<br />
Zip code: <asp:TextBox id="txtZipCode" runat="server" />
<br />
<asp:Label id="lblMsg" runat="server" />
<asp:Button id="btn" onclick="Click_Validate" runat="server" text="go" />
</form>
</body>
</html>