 |
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

December 14th, 2006, 09:14 AM
|
Friend of Wrox
|
|
Join Date: Aug 2006
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

December 14th, 2006, 09:29 AM
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
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
|

December 14th, 2006, 09:45 AM
|
Friend of Wrox
|
|
Join Date: Aug 2006
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

December 14th, 2006, 09:49 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
hi there..
try with server.transfer instead of response.redirect...
HTH
Gonzalo
|

December 14th, 2006, 09:52 AM
|
Friend of Wrox
|
|
Join Date: Aug 2006
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
sorry Mr.Gonzalo, its also not working
|

December 14th, 2006, 09:59 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
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
|

December 14th, 2006, 10:03 AM
|
Friend of Wrox
|
|
Join Date: Aug 2006
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

December 14th, 2006, 10:14 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
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
|

December 14th, 2006, 10:20 AM
|
Friend of Wrox
|
|
Join Date: Aug 2006
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

December 14th, 2006, 10:28 AM
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
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
|
|
 |