Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 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
 
Old November 27th, 2006, 04:27 AM
Authorized User
 
Join Date: Nov 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to use sessions to remember logged on user?

Hi comrades.
I am a university student and
I really need to know:


I- How can i make my application to [u]remember logged on user via sessions</u>? are sessions and cookies same?
II- How can i make application [u]doesn't allow non-member users</u> to enter member areas?

I am waiting for your help friends.
Thanks a lot!

 
Old November 27th, 2006, 05:05 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

You have to use the authentication (either Forms or Windows) to force the user to login

This can be done using the WebConfig file and couple of login controls available in VS2005 or VWD2KEE

Here is the sample for Forms Authentication in WebConfig file

<authentication mode="Forms">
   <forms name="AuthCookie" loginUrl="Login.aspx" defaultUrl="Home.aspx" timeout="10" />
  </authentication>

<authorization>
   <deny users="?" />
</authorization>


Try to include the login controls over a new ASP.net Page

Shasur

http://www.vbadud.blogspot.com
 
Old November 29th, 2006, 11:03 AM
Friend of Wrox
 
Join Date: Feb 2006
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
Default

To answer your first question, cookies are not the same as sessions. Rather cookies can be used to implement sessions. In order to implement sessions for a given website, your web server must be able to identify each HTTP request uniquely and map it to a session. A session ID can be stored in a cookie, or a little text file, on each client that hits the website.

Neil Timmerman
Programmer
Veris Consulting
 
Old November 29th, 2006, 12:01 PM
Authorized User
 
Join Date: Sep 2006
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

HI ,
To make u clear , If u have 2 pages and want to share variable between these 2 pages .U can use session.
eg
session["username"] =" "raj"

then in second page u can get the values from session by

string name= session['username']

Once stored in session .It can be retrieved from any page. But obly for single user.

cookies are a small file in users machine. we can store some small information in cookies.So that if next time the user visits from same machine.we can tell , that the user is already visited our site.

 
Old November 30th, 2006, 02:58 AM
Authorized User
 
Join Date: Nov 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by SriRamaKrishna
 HI ,
To make u clear , If u have 2 pages and want to share variable between these 2 pages .U can use session.
eg
session["username"] =" "raj"

then in second page u can get the values from session by

string name= session['username']

Once stored in session .It can be retrieved from any page. But obly for single user.

cookies are a small file in users machine. we can store some small information in cookies.So that if next time the user visits from same machine.we can tell , that the user is already visited our site.

Thanks, but i have done it before and it did not work :(
are you sure when we want to get value from session we should put attribute name among ' and '? (string name= session['username'])
maybe mine did not work because i let the attribute name between " and "!!!

 
Old November 30th, 2006, 09:21 AM
Authorized User
 
Join Date: Sep 2006
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi , Sorry , Its Typo . Double quote is the way to enclose string.

 
Old December 7th, 2006, 04:17 AM
Authorized User
 
Join Date: Nov 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hey...i could resolve my problem but i have another problem:
i define a string variable in my class (C#)and use it from my page_load... event like this:


Class mypage.... {
String mysession;
protected void page_load {
mysession=session["name"].tostring();
label1.text=mysession;
.
.
.
}

i can just use the variable mysession from page_load. when i run my application label1 shows value of the session.
but i can't use that string variable in another method:

pretected void button_click..... {
label2.text=this.mysession;
...
..
.
}

there is nothing in the string variable and when i run my application i see nothing in the label2 control....
what's it's problem?





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
Displaying sessions logged into Win2K Server sachin1979 BOOK: Beginning ASP 3.0 0 September 5th, 2004 08:04 PM
Getting the name of the logged on user Grahame2003 C# 2 March 4th, 2004 04:48 AM





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