Exactly....I have done that,bt the thing is whenever I click Back Button which is on Explorer at left cornr again the control goes to the Home page.....Instead I want that the Login page should be refreshed once I logout from my account...
and in login.aspx page load event ... write the following statement...
Response.Cache.SetNoStore();
it should be the first statement in the page load event.... if you are using the master pages then write the above statement in the master page load event....
Manjusha Sar...
Member
13 Points
108 Posts
Logout code in c#
May 26, 2009 12:15 PM|LINK
I want to logout from my account totally and return control to the Login page
atiface
Member
424 Points
71 Posts
Re: Logout code in c#
May 26, 2009 12:38 PM|LINK
If you are using forms authentication then you can use FormsAuthentication.SignOut();
this will work as long as you have set up ur website for form authentication in the config like this:
<authentication mode="Forms">
<forms loginUrl="~/login.aspx" slidingExpiration="false" cookieless="AutoDetect" timeout="20" protection="All" enableCrossAppRedirects="false" defaultUrl="~/authenticated.aspx"></forms>
</authentication>
If you using some other mechanism e.g. some session based thing then you do this
Session.Abandon(); and then you can Response.Redirect("~/logn.aspx") i.e to you login page.
--------------------------
No Fate but what we make.
cgeers
Contributor
2075 Points
278 Posts
Re: Logout code in c#
May 26, 2009 12:40 PM|LINK
Try:
// Remove the forms-authentication ticket from the browser
FormsAuthentication.SignOut();
// Redirects the browser to the login URL
FormsAuthentication.RedirectToLoginPage();
More information is available on MSDN:
http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.signout.aspx
http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.redirecttologinpage.aspx
Check out my blog
jacobodolil
Participant
868 Points
228 Posts
Re: Logout code in c#
May 26, 2009 02:48 PM|LINK
FormsAuthentication.SignOut();
Session["Name"].Abandon();Response.Redirect(
"Home.aspx");Jacob
Mark As Answer if this post Helped you
Manjusha Sar...
Member
13 Points
108 Posts
Re: Logout code in c#
May 27, 2009 04:09 AM|LINK
Exactly....I have done that,bt the thing is whenever I click Back Button which is on Explorer at left cornr again the control goes to the Home page.....Instead I want that the Login page should be refreshed once I logout from my account...
getchinna_sv
Star
12043 Points
2096 Posts
Re: Logout code in c#
May 27, 2009 05:28 AM|LINK
Write the following logout code.... in logout button click event
FormsAuthentication.SignOut();
Session["Name"].Abandon();
Response.Redirect("Login.aspx");
and in login.aspx page load event ... write the following statement...
Response.Cache.SetNoStore();
it should be the first statement in the page load event.... if you are using the master pages then write the above statement in the master page load event....Manjusha Sar...
Member
13 Points
108 Posts
Re: Logout code in c#
May 27, 2009 05:37 AM|LINK
Hi Sir,
May i know what is this "NAME" for and when i run the webpage the following error is occoured
'object' does not contain a definition for 'Abandon' and no extension method 'Abandon' accepting a first argument of type 'object' could be found
aditya1986
Contributor
4168 Points
760 Posts
Re: Logout code in c#
May 27, 2009 05:45 AM|LINK
you follow above link
http://www.codeproject.com/KB/aspnet/NoCaching.aspx
or follow this code
if (Session["UserLogin"] != null)
{
Session.Clear();
Response.Write("<script language=javascript>var wnd=window.open('','newWin','height=1,width=1,left=900,top=700,status=no,toolbar=no,menubar=no,scrollbars=no,maximize=false,resizable=1');</script>");
Response.Write("<script language=javascript>wnd.close();</script>");
Response.Write("<script language=javascript>window.open('Doctlog.aspx','_parent',replace=true);</script>");
}
i hope it helps you
-----------------------------------
MARK AS ANSWER if post helps you
jacobodolil
Participant
868 Points
228 Posts
Re: Logout code in c#
May 27, 2009 10:29 AM|LINK
Hi Manjusha
Here the Session["Name"] where name is the name of the session where the user details is stored and we are disposing the session variable on logout.
you may also use
Session["Name"].Clear();
Jacob
Mark As Answer if this post Helped you
jacobodolil
Participant
868 Points
228 Posts
Re: Logout code in c#
May 27, 2009 10:32 AM|LINK
Hi
You must clear your cache inoder to prevent the browser being displaying the previous page on back button.
Jacob
Mark As Answer if this post Helped you