Paladine, thanks for your help so far. As of now, my login pages load in Visual QWeb Developer Express (Only validation works, and when i login with user id and pw, the page just reloads with the pw text field blank again. I dont get an error connecting to database or anything). However, when I check it out on the server, i get a big configration error. It is something like :
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.
Source Error:
Line 6: Line 7: <system.web>Line 8: <roleManager enabled="true" />Line 9: <authentication mode="Forms" />Line 10: <compilation defaultLanguage="vb" debug="true" />
Below is my full web.config file. (not as same as yours, but does it need to be just with the source file location changed?)
<configuration>
<appSettings>
<addkey="strnConn"value="PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=D:\Inetpub\wwwroot\students\teamg\IUser\teamg.mdb;User ID=Admin;Password=;" />
</appSettings>
<system.web>
<roleManagerenabled="False" />
<authenticationmode="Forms" />
<compilationdefaultLanguage="vb"debug="true" />
<customErrorsmode="Off" />
<traceenabled="true"requestLimit="10"pageOutput="true"traceMode="SortByTime"localOnly="false" />
</system.web>
<connectionStrings>
<addname="myConnection"connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Inetpub\wwwroot\students\teamg\IUser\teamg.mdb;Persist Security Info=True"
providerName="System.Data.OleDb"/>
</connectionStrings>
</configuration>
I have used your query for MS access, your same form code, and same functions in my login.aspx.vb file, (mostly cut and paste). Im not sure what is causing this error?
Also, I would like to redirect a validaded user from my Acess Database to my menu.aspx page Any help would be appreciated.
Imports System.Web.Security ' ||||| Required Class for Authentication Imports System.Data ' ||||| DB Accessing Import Imports System.Data.OleDb ' |||||| Access Database Required Import! Imports System.Configuration ' |||||| Required for Web.Config appSettings ||||| Partial Class Login Inherits System.Web.UI.Page Function DBConnection(ByVal strUserName As String, ByVal strPassword As String) As Boolean '<sumamry> ' ||||| Declare Required Variables ' ||||| Access appSettings of Web.Config for Connection String (Constant) '</summary> ' ||||| First is the Connection Object for an Access DB Dim MyConn As OleDbConnection = New OleDbConnection(System.Configuration.ConfigurationManager.AppSettings("strConn")) '<sumamry> ' ||||| Create a OleDb Command Object ' ||||| Pass in Stored procedure ' ||||| Set CommandType to Stored Procedure '</summary> ' ||||| To Access a Stored Procedure in Access - Requires a Command Object Dim MyCmd As New OleDbCommand("sp_ValidateUser", MyConn) ' ||||| Create Parameter Objects for values passed in Dim objParam1, objParam2 As OleDbParameter '<sumamry> ' ||||| Add the parameters to the parameters collection of the ' ||||| command object, and set their datatypes (OleDbType in this case) '</summary> objParam1 = MyCmd.Parameters.Add("@UserName", OleDbType.Char) objParam2 = MyCmd.Parameters.Add("@Password", OleDbType.Char) '' ||||| Set the direction of the parameters...input, output, etc objParam1.Direction = ParameterDirection.Input objParam2.Direction = ParameterDirection.Input '' ||||| Set the value(s) of the parameters to the passed in values objParam1.Value = strUserName objParam2.Value = strPassword ' ||||| Try, catch block! Try ' ||||| Check if Connection to DB is already open, if not, then open a connection If MyConn.State = ConnectionState.Closed Then ' ||||| DB not already Open...so open it MyConn.Open() End If ' ||||| Create OleDb Data Reader Dim objReader As OleDbDataReader objReader = MyCmd.ExecuteReader(CommandBehavior.CloseConnection) ' ||||| Close the Reader and the Connection Closes with it While objReader.Read() If CStr(objReader.GetValue(0)) <> "1" Then lblMessage.Text = "Invalid Login!" Else objReader.Close() ' ||||| Close the Connections & Reader Return True End If End While Catch ex As Exception lblMessage.Text = "Error Connecting to Database!" End Try End Function Private Sub cmdSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSubmit.Click If Page.IsValid Then ' ||||| Meaning the Control Validation was successful! ' ||||| Connect to Database for User Validation ||||| If DBConnection(txtUserName.Text.Trim(), txtPassword.Text.Trim()) Then FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, False) ' ||||| default.aspx Page! Else ' ||||| Credentials are Invalid lblMessage.Text = "Invalid Login!" ' ||||| Increment the LoginCount (attempts) 'Session("LoginCount") = CInt(Session("LoginCount")) + 1 ' ||||| Determine the Number of Tries 'If Session("LoginCount").Equals(intMaxLoginAttempts) Then ' Response.Redirect("Denied.aspx") 'End If 'If CInt(Session("Num_of_Tries")) > 2 Then ' ||||| If Exceeds then Deny! ' Response.Redirect("Denied.aspx") 'End If End If End If End Sub End Class
I followed this tutorial to the t, I'm not sure why I keep getting "Invalid Log In" I'm not using the log in attempt part yet. Any suggestions?
ASP.NET Syntax (Toggle Plain Text)
Imports System.Web.Security ' ||||| Required Class for Authentication Imports System.Data ' ||||| DB Accessing Import Imports System.Data.OleDb ' |||||| Access Database Required Import! Imports System.Configuration ' |||||| Required for Web.Config appSettings ||||| Partial Class Login Inherits System.Web.UI.Page Function DBConnection(ByVal strUserName As String, ByVal strPassword As String) As Boolean '<sumamry> ' ||||| Declare Required Variables ' ||||| Access appSettings of Web.Config for Connection String (Constant) '</summary> ' ||||| First is the Connection Object for an Access DB Dim MyConn As OleDbConnection = New OleDbConnection(System.Configuration.ConfigurationManager.AppSettings("strConn")) '<sumamry> ' ||||| Create a OleDb Command Object ' ||||| Pass in Stored procedure ' ||||| Set CommandType to Stored Procedure '</summary> ' ||||| To Access a Stored Procedure in Access - Requires a Command Object Dim MyCmd As New OleDbCommand("sp_ValidateUser", MyConn) ' ||||| Create Parameter Objects for values passed in Dim objParam1, objParam2 As OleDbParameter '<sumamry> ' ||||| Add the parameters to the parameters collection of the ' ||||| command object, and set their datatypes (OleDbType in this case) '</summary> objParam1 = MyCmd.Parameters.Add("@UserName", OleDbType.Char) objParam2 = MyCmd.Parameters.Add("@Password", OleDbType.Char) '' ||||| Set the direction of the parameters...input, output, etc objParam1.Direction = ParameterDirection.Input objParam2.Direction = ParameterDirection.Input '' ||||| Set the value(s) of the parameters to the passed in values objParam1.Value = strUserName objParam2.Value = strPassword ' ||||| Try, catch block! Try ' ||||| Check if Connection to DB is already open, if not, then open a connection If MyConn.State = ConnectionState.Closed Then ' ||||| DB not already Open...so open it MyConn.Open() End If ' ||||| Create OleDb Data Reader Dim objReader As OleDbDataReader objReader = MyCmd.ExecuteReader(CommandBehavior.CloseConnection) ' ||||| Close the Reader and the Connection Closes with it While objReader.Read() If CStr(objReader.GetValue(0)) <> "1" Then lblMessage.Text = "Invalid Login!" Else objReader.Close() ' ||||| Close the Connections & Reader Return True End If End While Catch ex As Exception lblMessage.Text = "Error Connecting to Database!" End Try End Function Private Sub cmdSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSubmit.Click If Page.IsValid Then ' ||||| Meaning the Control Validation was successful! ' ||||| Connect to Database for User Validation ||||| If DBConnection(txtUserName.Text.Trim(), txtPassword.Text.Trim()) Then FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, False) ' ||||| default.aspx Page! Else ' ||||| Credentials are Invalid lblMessage.Text = "Invalid Login!" ' ||||| Increment the LoginCount (attempts) 'Session("LoginCount") = CInt(Session("LoginCount")) + 1 ' ||||| Determine the Number of Tries 'If Session("LoginCount").Equals(intMaxLoginAttempts) Then ' Response.Redirect("Denied.aspx") 'End If 'If CInt(Session("Num_of_Tries")) > 2 Then ' ||||| If Exceeds then Deny! ' Response.Redirect("Denied.aspx") 'End If End If End If End Sub End Class
hi hi! thanks for the reply Paladine about the table issue. The next thing i want to do is compare a username to a username in the database.
From this line: FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, False)
If i set to say: RedirectFromLoginPage(txtUserName.Text, True)
what does that do? and how can I compare this username in another page?
What I am trying to do is:
if the username = <temp username> then
load an empty form
else if username =<member's username> Then
Load form with member's details already there
im trying to create an update details page.
no idea how to access username thats being passed from the RedirectFromLoginPage...
cheers
Kevin
FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, False)
... If DBConnection(txtUserName.Text.Trim(), txtPassword.Text.Trim()) Then ...
Hi,
I have a question.
As I've been reading, you have a login page, that is set as default. So, when you go to the web page, this login page is the first one to load:
http://www.testpage.com will redirect to http://www.testpage.com/login.aspx
This page, will validate username and password. If it is successful, it will redirect you to Default.aspx: http://www.testpage.com/default.aspx
My question is ... what happens if you type straight in the url:
http://www.testpage.com/default.aspx ??
How do you prevent the user to access that page?
If there is no session or variable stored somewhere indicating user is logged in ... how you do allow/prevent access to default page? what about to other pages?
thanks,
Juan
Ok, I have had a number of people ask me how to prevent access to say the default.aspx page via the direct url, and you can prevent this in a number of ways. I have mentioned the use of cookies, but in the following example I will use another method of Session variables......
| DaniWeb Message | |
| Cancel Changes | |