0

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)

0

Is there a way to use this code in visual web developer or Visual studio 2005 .net2.0?

Thanks,
Mike

0

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

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

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

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 !!!

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>

aspx.vb file

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

and this is wat i did in web.config

<appSettings/>
    <connectionStrings>
        <add name="HDconn" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
    </connectionStrings>

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.....

Edited by pyTony: fixed formating

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

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

No worries Rich,

Good question. See page 2 of this tutorial on how to do just what you asked.

http://www.daniweb.com/techtalkforums/thread19303-2.html

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?)

<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 :S ). 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 :) .

0

Hey Benbujwah,

If you did do the CUT and PASTE with Visual Web Developer Express, then that is the cause of the error. This code is for .NET 1.0 or 1.1 ONLY and not .NET 2.0 (which is what Web Developer Express is based on).

I haven't provided the .NET 2.0 version simply because with all the start page, master.page, etc configurations and steps, you can do this pretty much with no code typing at all. Best to go to the tutorial section of Visual Web Developer home page and watch the training videos. Rather difficult to convert the how to video presentation to text how to.

Hope this helps.

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 :S ). 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 :) .

0

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?

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
0

hi,i'm newbie here.i'm doing sch project.
can you send me the code of how to create login function using visual studio 2005? because i have lots of errors now,so can you help?
thanks alot.
i have done my code halfway.

Imports System.Data
Imports System.Data.OleDb
Imports System.Configuration
Partial Class Custlogin
Inherits System.Web.UI.Page

Protected Sub btnSignin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSignin.Click
Dim myConn As New OleDbConnection
Dim myCmd As New OleDbCommand

myConn.ConnectionString = _
ConfigurationManager.ConnectionStrings("CustomerConnectionString").ConnectionString
Dim cmd As String
Dim oleDbCommand As New OleDbCommand("SELECT [ID] FROM [TableName] WHERE [username] = ? AND [Password] = ?", New OleDbCommand(connectionString))

Dim param1 As New OleDbParameter("@username", "usernameHere")

Dim param2 As New OleDbParameter("@password", "passwordHere")

oleDbCommand.Parameters.Add(param1)

oleDbCommand.Parameters.Add(param2)

myCmd.Connection = myConn

myConn.Open()
myCmd.ExecuteNonQuery()
myConn.Close()

myCmd.Dispose()
myConn.Dispose()

If result Is DBNull.Value = False Then

'we have the correct user in the database

End If


End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub
End Class

0

Yeah I had this problem too and it took me a bit to figure out that the code had a bug in it. When the code tries to verify connection to the database and it fails, it sets lblMessage.Text = "Error Connecting to Database!" Then when it returns to the previous sub it sets and of course the login fails, it changes lblMessage.Text = "Invalid Login!" on top of the bad connection error. I changed the following code to fix it. This way if it encounters the previous code it will not set it to something else.

Original Code:
' ||||| Credentials are Invalid
lblMessage.Text = "Invalid Login!"

Modified Code:
' ||||| Credentials are Invalid
If lblMessage.Text <> "Error Connecting to Database!" Then
lblMessage.Text = "Invalid Login!"
End If

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?

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
0

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

0

I have written a simple login app which will answer your question. Not matter what page you access it will redirect to the login page. So you can make all pages protected.
click here to read and download the sample app.

0

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

hi what is the answer to your question?i couldn't find it!!!!

0

Hello!

FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, False)

What does that mean?

How do I verify if the user is logged in or not yet? then redirect for log in again.....

Regards,

0

This is done in your code prior this statement. This is "validation" is done when you pass the username/password into the DBConnection Function:

...
If DBConnection(txtUserName.Text.Trim(), txtPassword.Text.Trim()) Then
...
0

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

The Answer to your very question about .. "How do I prevent direct access to the Default.aspx via URL entry..." is found in this very thread...

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......

Found here: http://www.daniweb.com/forums/thread19303-3.html


Hope that helps

0

Hi,

I talked about what is that"usename.txt" written for? Is that a cookies created when login success?

I did ask how to verify if user logged in or not.......it is about How to verify who is who? what user is logged in? How could I get the username which is currently logged in.

One more thing is that is it possible to redirect to the http_referer page after log in?

Regards,

0

Hi,

I talked about what is that"usename.txt" written for? Is that a cookies created when login success?

I did ask how to verify if user logged in or not.......it is about How to verify who is who? what user is logged in? How could I get the username which is currently logged in.

One more thing is that is it possible to redirect to the http_referer page after log in?

Regards,

UserName.text is the actual username text control which contains the original value typed by the user. Now if you want to track who is who. You can either use Cookies or Sessions.

Cookies and Sessions can be stored and retrieved to see who has logged in and you can redirect to the referring page after login.

0

Could you please write down some code for me? I got no idea how to deal with that.....m ASP.Net newbies.

Thanks,

0

i've created the login page.
i have problem to redirect page after successful login. the page redirect to default.aspx. how can i change the redirect page to page what i want after successful login?. i need my page to go to "~Client/Gan/Default.aspx".

i dont find the codes at login.aspx & web.config that i can change to redirect page. please help.

0

Hi,

I tried your example and there are no errors but when I click on log in it doesn't do anything. It just wipes out the password. I am trying to connect to a remote sql 2005 server.

Do I put the imports, functions, and db connection in the loign.aspx.vb?

Thanks

0

Hi,

I tried your example and there are no errors but when I click on log in it doesn't do anything. It just wipes out the password. I am trying to connect to a remote sql 2005 server.

Do I put the imports, functions, and db connection in the loign.aspx.vb?

Thanks

Whose reply are you referring here? If it is mine, then try to place a breakpoint and see if its coming to the function call and see what happens.

0

Binoj_daniel,

I tried to create the login page listed in your reply at http://www.coderewind.com/?categ&view_article=34. I am getting a error that the resource cannot be found. I have tried three times to get this to work. I am using VS 2008 because I don't see where you can create a "WEbsite" in VS 2005 as your first instruction indicates. Here is the error I get:

Server Error in '/SimpleLogin_coderewind' Application.
--------------------------------------------------------------------------------

The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /SimpleLogin_coderewind/logon.aspx


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053

I have renamed and recreated (deleting all previous versions) the project and/or website three times. Why is the application saying it can not find the file? This doesn't make sense to me. I have the project saved in c:/inetpub/wwwroot and the website saved at c:/documents and settings/username/my documents/visual studio 2008/websites/simplelogin_coderewind

I have no idea why .net is telling me it can't find the file.

Can you tell me how to fix this?

Thanks,

0

This is an issue with the path. See how it is mapping to an incorrect path. See if you can figure out.

Binoj_daniel,

I tried to create the login page listed in your reply at http://www.coderewind.com/?categ&view_article=34. I am getting a error that the resource cannot be found. I have tried three times to get this to work. I am using VS 2008 because I don't see where you can create a "WEbsite" in VS 2005 as your first instruction indicates. Here is the error I get:

I have renamed and recreated (deleting all previous versions) the project and/or website three times. Why is the application saying it can not find the file? This doesn't make sense to me. I have the project saved in c:/inetpub/wwwroot and the website saved at c:/documents and settings/username/my documents/visual studio 2008/websites/simplelogin_coderewind

I have no idea why .net is telling me it can't find the file.

Can you tell me how to fix this?

Thanks,

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.