?
Solved

send user to the right page

Posted on 2005-05-04
10
Medium Priority
?
174 Views
Last Modified: 2010-04-07
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
Comment
Question by:Ennio
  • 6
  • 4
10 Comments
 
LVL 12

Expert Comment

by:laotzi2000
ID: 13931833
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
 
LVL 1

Author Comment

by:Ennio
ID: 13932365
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
 
LVL 12

Expert Comment

by:laotzi2000
ID: 13932373
It should be added right before response.redirect
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:Ennio
ID: 13932403
so it should be like this


   FormsAuthentication.GetRedirectUrl(txtUsername.Text, False)
   response.Redirect()
Else
    myConn.Close()
    Label2.Text = "Invalid Username/Password"
End If
0
 
LVL 1

Author Comment

by:Ennio
ID: 13932414
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
 
LVL 12

Accepted Solution

by:
laotzi2000 earned 2000 total points
ID: 13932415
You should save it somewhere
like:
session("url")=FormsAuthentication.GetRedirectUrl(txtUsername.Text, False)
0
 
LVL 12

Expert Comment

by:laotzi2000
ID: 13932422
I think you did not set the authentication cookie after authenticate successfully
0
 
LVL 1

Author Comment

by:Ennio
ID: 13932435
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
 
LVL 1

Author Comment

by:Ennio
ID: 13934957
Can some one give a help here on how to setup the login in the right way, please?
0
 
LVL 1

Author Comment

by:Ennio
ID: 13935092
I think i got it.. i let you know
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month13 days, 20 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question