473,396 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

session problem

Hi friends,

I am designing a log in page. It contains user name and password fields, and a submit button.
So user enters user id, password and clicks submit button and he will be logged in. He will be redirected to inbox page.

Now if he click the logout button, he will be logged out and will be redirected to login page.
This is the scenario.

But my problem is after user cliked logout button, if he clicks back,forward buttons in Internet Explorer, he is still able to log in automatically.

Infact my session creation approach may be very wrong. Please correct me

My code is here

Default.aspx :


protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text == "ravi" && TextBox2.Text == "programmer")
{
Session["a"] = "session1";

Response.Redirect("Default2.aspx");
}
}




Default2.aspx :



protected void Page_Load(object sender, EventArgs e)
{
if (Session["a"] == null)
{

Response.Redirect("Default.aspx");
}
else
{

Response.Write("welcome to page");

}


}
protected void Logout_Click(object sender, EventArgs e)
{
Session.Remove("a");

Response.Redirect("Default.aspx");
}
May 8 '08 #1
5 1055
shweta123
692 Expert 512MB
Hi,

In order to solve your problem please write this line of code in Logout_Click() procedure :

Expand|Select|Wrap|Line Numbers
  1. Session.Abandon();
This will abandon the session.

Hi friends,

I am designing a log in page. It contains user name and password fields, and a submit button.
So user enters user id, password and clicks submit button and he will be logged in. He will be redirected to inbox page.

Now if he click the logout button, he will be logged out and will be redirected to login page.
This is the scenario.

But my problem is after user cliked logout button, if he clicks back,forward buttons in Internet Explorer, he is still able to log in automatically.

Infact my session creation approach may be very wrong. Please correct me

My code is here

Default.aspx :


protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text == "ravi" && TextBox2.Text == "programmer")
{
Session["a"] = "session1";

Response.Redirect("Default2.aspx");
}
}




Default2.aspx :



protected void Page_Load(object sender, EventArgs e)
{
if (Session["a"] == null)
{

Response.Redirect("Default.aspx");
}
else
{

Response.Write("welcome to page");

}


}
protected void Logout_Click(object sender, EventArgs e)
{
Session.Remove("a");

Response.Redirect("Default.aspx");
}
May 8 '08 #2
Thank you for response.

No, it didnt solve my problem. when i click back button in IE after logout, still it allows user automatically to inbox page(welcome page).

is my session creation approach is correct?
or should i make other way?

Hi,

In order to solve your problem please write this line of code in Logout_Click() procedure :

Expand|Select|Wrap|Line Numbers
  1. Session.Abandon();
This will abandon the session.
May 9 '08 #3
Curtis Rutland
3,256 Expert 2GB
Thank you for response.

No, it didnt solve my problem. when i click back button in IE after logout, still it allows user automatically to inbox page(welcome page).

is my session creation approach is correct?
or should i make other way?
I've run into a problem like this before. When you click back, the browser is most likely using the cached page, not reloading it. Therefore, the Page_Load code isn't being run. The session is destroyed (if you use the Session.Abandon() method), but the cached pages remain on the local machine. If you were to refresh the browser after you click back, it should behave in the manner expected.

I'm not quite sure how to fix that. What I did to overcome this was include a function on my master page to check if the session is valid on Page_Load. That way, they could go "Back" and "Forward" all they want, but if they clicked any link or caused a postback, they would get bounced back to the login page.
May 9 '08 #4
kenobewan
4,871 Expert 4TB
Have you tried redirecting the page after abandoning the session? .Net 2.0 does a better job with the login status control.
May 9 '08 #5
hi friends this has helped me:

Put the following code in the pages you don't want client browser to cache.

Response.CacheControl = "no-cache";
Response.Expires = -1;
May 9 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Billy Jacobs | last post by:
I am having a problem with my session variable being set to Null for no apparent reason. I am declaring it like the following when the user logs in. dim objUserInfo as new clsUserInfo 'Set...
1
by: Scott Wickham | last post by:
I'm having a problem saving session information on one form and retrieving it on a subsequent form...for only one out of a number of users. Actually, I'm not absolutely certain it's a session...
6
by: Lina Manjarres | last post by:
Hello, I have a session variable in a login page. Then I go to a form page where I uses the ProfileID and the UserID. Then I go to a result page where I would like to use the UserID as a filter,...
7
by: Ottar | last post by:
I've made a program sorting incomming mail in public folder. The function runs every minute by using the form.timer event. In Access XP it runs for weeks, no problem. Access 2003 runs the same...
5
by: Mark Rodrigues | last post by:
Hi Everyone, I have been fighting a problem for a while and I wonder if someone out there can help. This problem has been presented in a number of news postings previously but I am yet to see a...
9
by: William LaMartin | last post by:
I have a problem, mentioned here before, of Session and Application variables disappearing at one site but not at others or on my development computer. The problem is illustrated by an example...
1
by: Werner | last post by:
Hi Patrick! Can you give an example of how to use a frameset inside an aspx-file? When I create a new frameset in Visual Studio.Net it just gives me a htm-File. Or give me a link where I can...
1
by: Johan Nedin | last post by:
Hello! I have a problem with SQLSession state on my ASP.NET pages. SQLSession state behaves very different from InProcess session state, which I think is very bad. I can understand some of...
5
by: Just D. | last post by:
Do we have any access to the Session object from a different Session? The idea is to save Session of a current user and then if he logs in again then return the Session back. It's not a problem to...
7
by: Mr Newbie | last post by:
I have written a Custom Control Menu. Its fairly simple but it works well enough. In order to simplify things I decided to store the Menu1 custom control in Session. In the page load event below,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.