Ennio
asked on
send user to the right page
I have two pages on my website that needs login, so if you go to the page and don't have the permission it will send you to the login page. Now on my login page I have hard code after the user logs in go to the index.aspx page, but since I'm using the same login page for all the password protected page how can I send the user to the last page he visited.
ASKER
where should I add that?
should I add on my page load? or on my response.redirect??
here is part of the code
*******************
<script language="vb" runat="server">
Sub Page_Load (s As Object, e As EventArgs)handles mybase.load
If Not isPostBack Then
Session.Item("uname") = ""
End If
End Sub
....
Sub btnSubmit_Click(sender As Object, e As EventArgs)
....
response.Redirect()
Else
myConn.Close()
Label2.Text = "Invalid Username/Password"
End If
should I add on my page load? or on my response.redirect??
here is part of the code
*******************
<script language="vb" runat="server">
Sub Page_Load (s As Object, e As EventArgs)handles mybase.load
If Not isPostBack Then
Session.Item("uname") = ""
End If
End Sub
....
Sub btnSubmit_Click(sender As Object, e As EventArgs)
....
response.Redirect()
Else
myConn.Close()
Label2.Text = "Invalid Username/Password"
End If
It should be added right before response.redirect
ASKER
so it should be like this
FormsAuthentication.GetRed irectUrl(t xtUsername .Text, False)
response.Redirect()
Else
myConn.Close()
Label2.Text = "Invalid Username/Password"
End If
FormsAuthentication.GetRed
response.Redirect()
Else
myConn.Close()
Label2.Text = "Invalid Username/Password"
End If
ASKER
Hum I was looking and I think I'm doing something wrong here, here is the full code. I'm new to asp .net
am I doing this right?
************************** ********** ********** ********** ********** ********** **
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859 -1" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Ole Db" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script language="vb" runat="server">
Sub Page_Load (s As Object, e As EventArgs)handles mybase.load
If Not isPostBack Then
Session.Item("uname") = ""
End If
End Sub
Sub btnSubmit_Click(sender As Object, e As EventArgs)
If Page.IsValid Then
Dim myConn As OleDbConnection
Dim myComm As OleDbCommand
myConn = New OleDbConnection("Provider= Microsoft. Jet.OLEDB. 4.0; Data Source = " & Server.MapPath("/database/ babysitter .mdb") & ";")
myConn.Open()
myComm = New OleDbCommand("Select * from tbl_babysitter where email='" & txtuname.text & "' and passwd='" & txtpwd.Text & "'", myConn)
If (myComm.ExecuteReader().Ha sRows() ) then
Session.Add("uname", txtuname.text)
myConn.Close()
response.Redirect("index.a spx")
Else
myConn.Close()
Label2.Text = "Invalid Username/Password"
End If
Else
Label2.Text = "You must enter the required fields"
End If
End Sub
</script>
</head>
<body>
<form runat="server">
<asp:Label ID="Label2" runat="server"/><br />
Username:
<asp:TextBox ID="txtuname" TextMode="SingleLine" runat="server" />
<br>
Password:
<asp:TextBox ID="txtpwd" TextMode="Password" runat="server" />
<asp:Button ID="btnsubmit" runat="server" OnClick="btnSubmit_Click" Text="Ok" />
</form>
</body>
</html>
am I doing this right?
**************************
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Ole
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script language="vb" runat="server">
Sub Page_Load (s As Object, e As EventArgs)handles mybase.load
If Not isPostBack Then
Session.Item("uname") = ""
End If
End Sub
Sub btnSubmit_Click(sender As Object, e As EventArgs)
If Page.IsValid Then
Dim myConn As OleDbConnection
Dim myComm As OleDbCommand
myConn = New OleDbConnection("Provider=
myConn.Open()
myComm = New OleDbCommand("Select * from tbl_babysitter where email='" & txtuname.text & "' and passwd='" & txtpwd.Text & "'", myConn)
If (myComm.ExecuteReader().Ha
Session.Add("uname", txtuname.text)
myConn.Close()
response.Redirect("index.a
Else
myConn.Close()
Label2.Text = "Invalid Username/Password"
End If
Else
Label2.Text = "You must enter the required fields"
End If
End Sub
</script>
</head>
<body>
<form runat="server">
<asp:Label ID="Label2" runat="server"/><br />
Username:
<asp:TextBox ID="txtuname" TextMode="SingleLine" runat="server" />
<br>
Password:
<asp:TextBox ID="txtpwd" TextMode="Password" runat="server" />
<asp:Button ID="btnsubmit" runat="server" OnClick="btnSubmit_Click" Text="Ok" />
</form>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I think you did not set the authentication cookie after authenticate successfully
ASKER
I think so, because in my other pages I just check for the Session.Item("uname") = to some data, and they get the permission to the page.
ASKER
Can some one give a help here on how to setup the login in the right way, please?
ASKER
I think i got it.. i let you know
get the url by:
FormsAuthentication.GetRed
Then you can save this somewhere, and in index.aspx, redirect to the saved page.