Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 14th, 2006, 09:14 AM
Friend of Wrox
 
Join Date: Aug 2006
Location: norcross, Ga, USA.
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Default to keep the user logged in until he sign out

hi all,

how can i set the application, so that once the user get signed in, he should be signed in until he sign out.?
ie, after signing in the login screen should not display until he sign out.
now what is the situation is, he places order, it ask for username and passowrd, he signs in, and then again if he do somemore shopping and added the products to his cart, and hit Place order button, it again asks for username and password.

in the sign in button i have used this
  FormsAuthentication.RedirectFromLoginPage(txtuser. Text, Persistent.Checked)

still it ask for sign in!!!

how can i avoid this?
hope someone shares their idea!!!

thanks to p2p forum members

  #2 (permalink)  
Old December 14th, 2006, 09:29 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Sounds like a logic problem;

Try this instead:

if(User.Identity.IsAuthenticated)
{
   //dont display login screen
}
else
{
  //display login screen
}

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
  #3 (permalink)  
Old December 14th, 2006, 09:45 AM
Friend of Wrox
 
Join Date: Aug 2006
Location: norcross, Ga, USA.
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi

i tried ur logic, and my modified code is below. but its not getting redirected to the login page or the default page, when i hit the button for placing order, instead the values are lost from the cart.

 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim ds As New DataSet
        ds = ShoppingCart.shopcart.GetAll(Session.SessionID)

        If (ds.Tables(0).Rows.Count = 0) Then

            Response.Redirect("EmptyPage.aspx")


            If (User.Identity.IsAuthenticated) Then

                          Response.Redirect("default.aspx")

            Else


                Response.Redirect("login.aspx")


            End If
        End If

    End Sub

  #4 (permalink)  
Old December 14th, 2006, 09:49 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there..

try with server.transfer instead of response.redirect...

HTH

Gonzalo
  #5 (permalink)  
Old December 14th, 2006, 09:52 AM
Friend of Wrox
 
Join Date: Aug 2006
Location: norcross, Ga, USA.
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Default

sorry Mr.Gonzalo, its also not working

  #6 (permalink)  
Old December 14th, 2006, 09:59 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

there has to be another problem here.. maybe with the configuration of the application...
are you using the standard login controls??
b/c when you login in the session should remain logged...


HTH

Gonzalo
  #7 (permalink)  
Old December 14th, 2006, 10:03 AM
Friend of Wrox
 
Join Date: Aug 2006
Location: norcross, Ga, USA.
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi, the code which i using to get the userid as return for the storedprocedure, by supplying username and password is below.

please have a look at this, and suggest where have i gone wrong?

 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If LoginUser(txtuser.Text, txtpass.Text) Then

            'FormsAuthentication.RedirectFromLoginPage(txtuser .Text, False)
            FormsAuthentication.RedirectFromLoginPage(txtuser. Text, Persistent.Checked)


        Else
            lblmessage.Text = "Invalid login credentials, try again!!!"

        End If


    End Sub


    Function LoginUser(ByVal struser As String, ByVal strpass As String) As Boolean

        Dim con As New SqlConnection("")

        Dim mycmd As New SqlCommand("spLoginUser", con)

        mycmd.CommandType = CommandType.StoredProcedure

        'adding parameters to stored procedure

        Dim P1 As SqlParameter = New SqlParameter("@UserName", SqlDbType.VarChar)
        P1.Value = struser
        mycmd.Parameters.Add(P1)

        Dim P2 As SqlParameter = New SqlParameter("@Password", SqlDbType.VarChar)
        P2.Value = strpass
        mycmd.Parameters.Add(P2)


        Try
            con.Open()
            Dim userid As Integer
            userid = mycmd.ExecuteScalar
            Session("UserID") = userid


            If userid = 0 Then

                Return 0

            Else
                Return userid

            End If

        Catch ex As Exception

            Response.Write("Error in connecting, try later")

        Finally
            If con.State = ConnectionState.Open Then
                con.Close()

            End If

        End Try

    End Function

  #8 (permalink)  
Old December 14th, 2006, 10:14 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there.. you are not using User.Identity to login the user, you have your own controls for it... replace that with Session("UserID") <> 0 and try now...

HTH

Gonzalo
  #9 (permalink)  
Old December 14th, 2006, 10:20 AM
Friend of Wrox
 
Join Date: Aug 2006
Location: norcross, Ga, USA.
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Default

one more question, this session("USerID") will get generated only after first the user get signed in.then for the first time, how can i go to login page?
because this button2_clcik is coded in the page just beofre the login page(where the shopping cart is displayed)
from there if the user clicks for placing order(button2) it gets redirected to login page.

am i confusing everyone??? i am sorry for that

  #10 (permalink)  
Old December 14th, 2006, 10:28 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Again this seems like a logic problem; by design, as far as Forms Authentication goes, once a user logs in they will stay logged in either until the browser window is closed, the user deletes the cookie that your application creates, or after 50 years have passed (depending on what value you pass to the bool argument).


This code is also poorly wrote:

     Dim ds As New DataSet
        ds = ShoppingCart.shopcart.GetAll(Session.SessionID)

        If (ds.Tables(0).Rows.Count = 0) Then

            Response.Redirect("EmptyPage.aspx")


            If (User.Identity.IsAuthenticated) Then

                         Response.Redirect("default.aspx")

            Else

            
                Response.Redirect("login.aspx")


            End If
        End If

It should be something like

     Dim ds As New DataSet
        ds = ShoppingCart.shopcart.GetAll(Session.SessionID)
        If (ds.Tables(0).Rows.Count = 0) Then
         Response.Redirect("EmptyPage.aspx")
         Exit Sub
        Else
            If (User.Identity.IsAuthenticated) Then Response.Redirect("default.aspx")
            Else: Response.Redirect("login.aspx")
            End If
        End If

If your dataset is empty the user being logged in is a moot point.

IMHO, I think the logic you are using for your application is weird and am having a hard time figuring out what you are doing.

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I check whether a user is logged in or out rittwick PHP Databases 1 August 19th, 2007 04:47 PM
user logged jonyBravo Access 6 November 27th, 2006 09:14 AM
Username of logged in user spardoe BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 4 August 18th, 2006 01:13 AM
Getting the name of the logged on user Grahame2003 C# 2 March 4th, 2004 04:48 AM



All times are GMT -4. The time now is 11:41 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.