Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 147437 | Replies: 145
![]() |
•
•
•
•
Perahaps I am still a newbie but where do you put the imports @?
Thanks,
Mike
Hi Mike,
I would review the tutorial section at the top of this thread for the step by step procedure, but bascially the imports are placed at the top of the code behind page or top of the script section at the top of the page. Depending on the method you are using. ASP.NET 1.0 or 1.1 specifically.
•
•
•
•
b.Code the "meat" of the Login in page.
- Mine is in the code behind rather than a script block, but the principles are the same.
- Add the following Imports to your code behind, just above the class declaration.
Code:
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 |||||
This will provide the library imports you need for Authentication, accessing an OleDB (i.e. Access), and accessing the web.config file (contains your connection string)
Assistant Manager, Regional Pharmacy Information Systems
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
•
•
•
•
Is there a way to use this code in visual web developer or Visual studio 2005 .net2.0?
Thanks,
Mike
Hi Mike,
Visual Web Develper or Visual Studio 2005 is in ASP.Net 2.0 and not 1.1. So some modification of this code would need to be done, as there are some differences which makes this code non-functional.
I highly recommend you go to this link and watch and walkthrough the tutorial videos.
LINK
I plan to post a ASP.Net 2.0 login tutorial very soon, now that my work project has concluded.
Thanks
Assistant Manager, Regional Pharmacy Information Systems
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
•
•
Join Date: Nov 2006
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
hi paladin
can you send me the code modifications to make the login page in visual Studio 2.0?
becouse i wrote your code but when i debug the pc find some errors.
do you have code in 2.0 for login page?
thanks a lot
ponchohq@gmail.com
can you send me the code modifications to make the login page in visual Studio 2.0?
becouse i wrote your code but when i debug the pc find some errors.
do you have code in 2.0 for login page?
thanks a lot
ponchohq@gmail.com
•
•
Join Date: Nov 2006
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
hi man
this is poncho. i wrote your code and made it run
but this line i can`t do work
SqlConnection(ConfigurationSettings.AppSettings("strConn"))
the debug send me an error
that say
sqlconnection is a type and can`t use like an expresion
if you can help me, i to be happy
i am development in visual studio 2005
contact: ponchohq@gmail.com
this is poncho. i wrote your code and made it run
but this line i can`t do work
SqlConnection(ConfigurationSettings.AppSettings("strConn"))
the debug send me an error
that say
sqlconnection is a type and can`t use like an expresion
if you can help me, i to be happy
i am development in visual studio 2005
contact: ponchohq@gmail.com
•
•
Join Date: Feb 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
hi..
Paladine i m using asp.net2.0 n was wonderin if u could provide the entire piece of this login page in asp.net 2.0 ...
thngs hav changed a bit in asp.net 2.0.....
would really appreciate if u continue this thread with asp.net2.0......
here is wat i did.....
tell me wat i did wrong !!!
[code]
LOGIN PAGE ....apsx file
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %>
<!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 runat="server">
<title>Login</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR" />
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE" />
<meta content="JavaScript" name="vs_defaultClientScript" />
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema" />
</head>
<body>
<!-- ||||| Login Form ||||| -->
<form id="frmlogin" method="post" runat="server">
<table id="mainTable">
<tr>
<td>
<table class="t_border" id="loginTable" cellspacing="15" cellpadding="0">
<tr>
<td><b>Login: </b>
</td>
<td><asp:textbox id="txtUserName" runat="server" width="160px"></asp:textbox><asp:requiredfieldvalidator id="rvUserValidator" runat="server" display="None" errormessage="You must supply a Username!"
controltovalidate="txtUserName"></asp:requiredfieldvalidator></td>
</tr>
<tr>
<td><b>Password: </b>
</td>
<td><asp:textbox id="txtPassword" runat="server" width="160px" textmode="Password"></asp:textbox><asp:requiredfieldvalidator id="rvPasswordValidator" runat="server" display="None" errormessage="Empty Passwords not accepted"
controltovalidate="txtPassword"></asp:requiredfieldvalidator></td>
</tr>
<tr>
<td align="center" colspan="2"><asp:button id="cmdSubmit" runat="server" borderstyle="Solid" text="Submit" OnClick ="button_click"></asp:button>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table id="messageDisplay">
<tr>
<td><asp:validationsummary id="Validationsummary1" runat="server" width="472px" displaymode="BulletList"></asp:validationsummary></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
<asp:label id="lblMessage" runat="server" width="288px" forecolor="#C00000" font-size="Medium"
font-italic="True" font-bold="True"></asp:label>
</body>
</html>
[code]
aspx.vb file
[code]
Partial Class Default2
Inherits System.Web.UI.Page
Protected Sub button_click(ByVal sender As 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)
Response.Redirect("default.aspx")
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
Public Function DBConnection(ByVal strUserName As String, ByVal strPassword As String) As Boolean
Dim MyConn As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("HDconn").ConnectionString)
'HDconn is my connectiostring from web.config
Dim MyCmd As New System.Data.SqlClient.SqlCommand("StoredProcedure1", MyConn)
MyCmd.CommandType = Data.CommandType.StoredProcedure
Dim objParam1, objParam2 As Data.SqlClient.SqlParameter
Dim objReturnParam As Data.SqlClient.SqlParameter
objParam1 = MyCmd.Parameters.Add("@UserName", System.Data.SqlDbType.VarChar)
objParam2 = MyCmd.Parameters.Add("@Password", System.Data.SqlDbType.VarChar)
objReturnParam = MyCmd.Parameters.Add("@Num_of_User", System.Data.SqlDbType.Int)
objParam1.Direction = System.Data.ParameterDirection.Input
objParam2.Direction = System.Data.ParameterDirection.Input
objReturnParam.Direction = System.Data.ParameterDirection.ReturnValue
objParam1.Value = txtUserName.Text
objParam2.Value = txtPassword.Text
Try
If MyConn.State = System.Data.ConnectionState.Closed Then
MyConn.Open()
MyCmd.ExecuteNonQuery()
End If
If objReturnParam.Value < 1 Then
lblMessage.Text = "Invalid Login!"
Else
Return True
End If
MyConn.Close()
Catch ex As Exception
'lblMessage2.Text = "Error Connecting to Database!"
End Try
End Function
End Class
[code]
and this is wat i did in web.config
[code]
<appSettings/>
<connectionStrings>
<add name="HDconn" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
[code]
but this thing always gives me......INVALID LOGIN.....
the table n stored procedure r exactly the same as u had posted earlier....
now can u plz tell me WHAT is exactly the prob.....
Paladine i m using asp.net2.0 n was wonderin if u could provide the entire piece of this login page in asp.net 2.0 ...
thngs hav changed a bit in asp.net 2.0.....
would really appreciate if u continue this thread with asp.net2.0......
here is wat i did.....
tell me wat i did wrong !!!
[code]
LOGIN PAGE ....apsx file
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %>
<!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 runat="server">
<title>Login</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR" />
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE" />
<meta content="JavaScript" name="vs_defaultClientScript" />
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema" />
</head>
<body>
<!-- ||||| Login Form ||||| -->
<form id="frmlogin" method="post" runat="server">
<table id="mainTable">
<tr>
<td>
<table class="t_border" id="loginTable" cellspacing="15" cellpadding="0">
<tr>
<td><b>Login: </b>
</td>
<td><asp:textbox id="txtUserName" runat="server" width="160px"></asp:textbox><asp:requiredfieldvalidator id="rvUserValidator" runat="server" display="None" errormessage="You must supply a Username!"
controltovalidate="txtUserName"></asp:requiredfieldvalidator></td>
</tr>
<tr>
<td><b>Password: </b>
</td>
<td><asp:textbox id="txtPassword" runat="server" width="160px" textmode="Password"></asp:textbox><asp:requiredfieldvalidator id="rvPasswordValidator" runat="server" display="None" errormessage="Empty Passwords not accepted"
controltovalidate="txtPassword"></asp:requiredfieldvalidator></td>
</tr>
<tr>
<td align="center" colspan="2"><asp:button id="cmdSubmit" runat="server" borderstyle="Solid" text="Submit" OnClick ="button_click"></asp:button>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table id="messageDisplay">
<tr>
<td><asp:validationsummary id="Validationsummary1" runat="server" width="472px" displaymode="BulletList"></asp:validationsummary></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
<asp:label id="lblMessage" runat="server" width="288px" forecolor="#C00000" font-size="Medium"
font-italic="True" font-bold="True"></asp:label>
</body>
</html>
[code]
aspx.vb file
[code]
Partial Class Default2
Inherits System.Web.UI.Page
Protected Sub button_click(ByVal sender As 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)
Response.Redirect("default.aspx")
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
Public Function DBConnection(ByVal strUserName As String, ByVal strPassword As String) As Boolean
Dim MyConn As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("HDconn").ConnectionString)
'HDconn is my connectiostring from web.config
Dim MyCmd As New System.Data.SqlClient.SqlCommand("StoredProcedure1", MyConn)
MyCmd.CommandType = Data.CommandType.StoredProcedure
Dim objParam1, objParam2 As Data.SqlClient.SqlParameter
Dim objReturnParam As Data.SqlClient.SqlParameter
objParam1 = MyCmd.Parameters.Add("@UserName", System.Data.SqlDbType.VarChar)
objParam2 = MyCmd.Parameters.Add("@Password", System.Data.SqlDbType.VarChar)
objReturnParam = MyCmd.Parameters.Add("@Num_of_User", System.Data.SqlDbType.Int)
objParam1.Direction = System.Data.ParameterDirection.Input
objParam2.Direction = System.Data.ParameterDirection.Input
objReturnParam.Direction = System.Data.ParameterDirection.ReturnValue
objParam1.Value = txtUserName.Text
objParam2.Value = txtPassword.Text
Try
If MyConn.State = System.Data.ConnectionState.Closed Then
MyConn.Open()
MyCmd.ExecuteNonQuery()
End If
If objReturnParam.Value < 1 Then
lblMessage.Text = "Invalid Login!"
Else
Return True
End If
MyConn.Close()
Catch ex As Exception
'lblMessage2.Text = "Error Connecting to Database!"
End Try
End Function
End Class
[code]
and this is wat i did in web.config
[code]
<appSettings/>
<connectionStrings>
<add name="HDconn" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
[code]
but this thing always gives me......INVALID LOGIN.....
the table n stored procedure r exactly the same as u had posted earlier....
now can u plz tell me WHAT is exactly the prob.....
•
•
Join Date: Mar 2007
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
Hi Paladine, that tutorial worked great and my login is now working from my Access DB
I don't know if i'm allowed to ask this question here, but here goes!
When the user has logged in and they are taken to the Default.aspx page i would like a 'Welcome [UserName goes here]' feature showing who they have successfully logged in as
I'm a complete newbie to ASP.Net and i'm sure it will be very easy for you to tell me
Thanks again
Rich
I don't know if i'm allowed to ask this question here, but here goes!
When the user has logged in and they are taken to the Default.aspx page i would like a 'Welcome [UserName goes here]' feature showing who they have successfully logged in as
I'm a complete newbie to ASP.Net and i'm sure it will be very easy for you to tell me
Thanks again
Rich
•
•
•
•
Hi Paladine, that tutorial worked great and my login is now working from my Access DB
I don't know if i'm allowed to ask this question here, but here goes!
When the user has logged in and they are taken to the Default.aspx page i would like a 'Welcome [UserName goes here]' feature showing who they have successfully logged in as
I'm a complete newbie to ASP.Net and i'm sure it will be very easy for you to tell me
Thanks again
Rich
No worries Rich,
Good question. See page 2 of this tutorial on how to do just what you asked.
http://www.daniweb.com/techtalkforum...ad19303-2.html
Assistant Manager, Regional Pharmacy Information Systems
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
•
•
Join Date: Apr 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
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?)
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
.
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
. ![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)





Linear Mode