Login - return back to original page

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello -

I have two places in my application where someone needs to be logged in. If
they are not logged in and I send them to the login page, how do I send them
back to the page they originally came from after they log in?

Any help will be greatly appreciated!
 
I have two places in my application where someone needs to be logged
in. If they are not logged in and I send them to the login page, how
do I send them back to the page they originally came from after they
log in?

ASP.NEt's Forms authentication handles URL redirection for you.
 
After you authenticate the user, you can call
FormsAuthentication.RedirectFromLoginPage

This will automagically redirect the user back to the page they want to
access.
 
Hi Tu-Thach!

Thanks for your response!

I tried including this in my code, but couldn't get it to work.

Here's my code. Where is it supposed to go? I kept getting the squiggly
blue line when I tried to put it in. At the top of the page, I included
Imports System.Web.Security

Private Sub btnSubmitLogin_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSubmitLogin.Click
Dim daTest as SqlDataAdapter
Dim dsLogin as New DataSet
daTest = New SqlDataAdapter("Select UserID from " _
& "tblLogin Where " _
& "UserName = '" & txtUserName.Text _
& "' and Password = '" & txtPassword.Text _
& "'", cnn)

daTest.Fill(dsLogin, "tblLogin")
If dsLogin.Tables("tblLogin").Rows.Count = 0 then
lblLoginStatus.Text = "User name and password not found. Please try
again."
Else
Session("UserID") = dsLogin.Tables("tblLogin").Rows(0).Item("UserID")
lblLoginStatus.Text = "Success!"

End If
End Sub
 
Hi Tu-Thach!

I tried including it in my code but couldn't get it to work. It just
redirected to default.aspx (which I don't even have).

Can you be more explicit on how to use it?

Here's my code:

Private Sub btnSubmitLogin_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSubmitLogin.Click
Dim daTest as SqlDataAdapter
Dim dsLogin as New DataSet
daTest = New SqlDataAdapter("Select UserID from " _
& "tblLogin Where " _
& "UserName = '" & txtUserName.Text _
& "' and Password = '" & txtPassword.Text _
& "'", cnn)

daTest.Fill(dsLogin, "tblLogin")
If dsLogin.Tables("tblLogin").Rows.Count = 0 then
lblLoginStatus.Text = "User name and password not found. Please try
again."
Else
Session("UserID") = dsLogin.Tables("tblLogin").Rows(0).Item("UserID")
'I put it in here. Something's obviously wrong
FormsAuthentication.RedirectFromLoginPage(txtUserName.Text,
Remember.Checked)
End If
End Sub
 
After your success check lblLoginStatus.Text = "Success!", you can add this
line

FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, false);

That will redirect the user to the page they want access.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top