• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 179
  • Last Modified:

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.
0
Ennio
Asked:
Ennio
  • 6
  • 4
1 Solution
 
laotzi2000Commented:
In your login page, when you are authenticating the user, you can
get the url by:
FormsAuthentication.GetRedirectUrl(txtUsername.Text, False)

Then you can save this somewhere, and in index.aspx, redirect to the saved page.
0
 
EnnioAuthor Commented:
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
0
 
laotzi2000Commented:
It should be added right before response.redirect
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
EnnioAuthor Commented:
so it should be like this


   FormsAuthentication.GetRedirectUrl(txtUsername.Text, False)
   response.Redirect()
Else
    myConn.Close()
    Label2.Text = "Invalid Username/Password"
End If
0
 
EnnioAuthor Commented:
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.OleDb" %>
<!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().HasRows() ) then
                  Session.Add("uname", txtuname.text)
                  myConn.Close()
                  response.Redirect("index.aspx")
            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>
0
 
laotzi2000Commented:
You should save it somewhere
like:
session("url")=FormsAuthentication.GetRedirectUrl(txtUsername.Text, False)
0
 
laotzi2000Commented:
I think you did not set the authentication cookie after authenticate successfully
0
 
EnnioAuthor Commented:
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.

0
 
EnnioAuthor Commented:
Can some one give a help here on how to setup the login in the right way, please?
0
 
EnnioAuthor Commented:
I think i got it.. i let you know
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now