Logout problem in application

Posted by Sathiya_Narayanan under ASP.NET on 6/26/2012 | Points: 10 | Views : 1877 | Status : [Member] | Replies : 13
Hi,

I am developing a web application there i have login & logout in that problem is after logout from the application if we click
the back button in browser again it comes to previous page, how to avoid this,
if any know pls show some examples.







Thanks,

SATHIYANARAYANAN


Responses

Posted by: .Netlearner on: 6/26/2012 [Member] Starter | Points: 25

Up
0
Down
Maintain Session Once u login

Session["UserName"]=txtuserName.Text;
use this code while u click login button and when u logout clear the session in the logout button click event as follows,

Session.Clear();

Session.Abandon();


Hope this vl work.

Mark this an answer if it works.

Sathiya_Narayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sathiya_Narayanan on: 6/26/2012 [Member] Starter | Points: 25

Up
0
Down
ok once when i logged in it should show the user name in top as how in dotnetfunda website how to do this task

SATHIYANARAYANAN

Sathiya_Narayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: .Netlearner on: 6/26/2012 [Member] Starter | Points: 25

Up
0
Down
Just use a label.And use the Session Created while u login to display the username in that label.The Code is as follows

lblwelcome.Text="Welcome "+ Session["UserName"].ToString();


Once u create the session in login u can use it anywhere in the application until u logout the application.

Sathiya_Narayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sathiya_Narayanan on: 6/26/2012 [Member] Starter | Points: 25

Up
0
Down
it shows error message

Compiler Error Message: CS0019: Operator '+' cannot be applied to operands of type 'string' and 'method group'

if u have any examples give some link.

SATHIYANARAYANAN

Sathiya_Narayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: .Netlearner on: 6/26/2012 [Member] Starter | Points: 25

Up
0
Down
No i have worked with this code its working.Check once whether u have mentioned parenthesis near ToString().if you missed it may cause similar error

lblwelcome.Text = "Welcome " + Session["UserName"].ToString();


Sathiya_Narayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sathiya_Narayanan on: 6/26/2012 [Member] Starter | Points: 25

Up
0
Down
ya first i dint put after i putting parenthesis its shows error

Object reference not set to an instance of an object.

SATHIYANARAYANAN

Sathiya_Narayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: .Netlearner on: 6/26/2012 [Member] Starter | Points: 25

Up
0
Down
ok in which line its showing an error where have u defined the Session["UserName"].

Sathiya_Narayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sathiya_Narayanan on: 6/26/2012 [Member] Starter | Points: 25

Up
0
Down
ok is in aspx page have to add any script for this sessions

SATHIYANARAYANAN

Sathiya_Narayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: .Netlearner on: 6/26/2012 [Member] Starter | Points: 25

Up
0
Down
no you dont have to add anything in aspx page

Sathiya_Narayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nuwan on: 6/27/2012 [Member] Starter | Points: 25

Up
0
Down
Please given this code

Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
FormsAuthentication.SignOut()
Response.Redirect(FormsAuthentication.LoginUrl)
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1))
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.Cache.SetNoStore()
End Sub

Rathnayake

Sathiya_Narayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bhupentiwari on: 6/27/2012 [Member] Starter | Points: 25

Up
0
Down
when you login set the session variable like this

session["UserName"] = UserName.text


Thanks n Regards
Bhupendra Tiwari

Sathiya_Narayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Johnbhatt on: 6/27/2012 [Member] Starter | Points: 25

Up
0
Down
Use a Masterpage and Open all pages if that have Valid Session, if session Expired, then Refresh Page and Logout User from Application.

You can use this in PageLoad event.

example code.

if(Session["UserName"]=="")

{
Response.Write("<script>alert('You are not Logged In, Redirecting you to Login Page!');</script>");
Response.Redirect("LoginPage.aspx");
}


John Bhatt
Glad to Know, Free to Share.....
http://www.johnbhatt.com

Sathiya_Narayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ajay.Kalol on: 6/27/2012 [Member] Starter | Points: 25

Up
0
Down
When you click Back button your page is displayed from browser Cache so you have to clear cache every time you logout. that will solve your Problem

Ajay
ajaypatelfromsanthal.blogspot.in

Sathiya_Narayanan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response