i m having problem with logout code in asp.net with c#. this logout code should end session, disable browser's back button and and if somebody try to login by paste the url of any user account page, he can't. plzzz help
i dint use FormAuthentication i just use C# code and redirect to differnt pages through links.... Helppp
U need to kill session on sign_out button click.
Write the beolw code on signout button click
session.RemoveAll();
Session.Abondon();
Response.ClearHeaders();
Response.Redirect("xyz.aspx");
Hope it helps.
Marked as answer by Abdul Muqeet on Jul 08, 2012 07:26 AM
i tried this code in logout button its redirecting to same page ..
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
if ((string)Session["QueryString"] == null)
{
Response.Redirect("login.aspx", true);
}
session.RemoveAll();
Session.Abondon();
Response.ClearHeaders();
Response.Redirect("xyz.aspx");
if (Session[name] == null)
{
Responce.Redirect(login.aspx);
}
this work fine
Marked as answer by Abdul Muqeet on Jul 08, 2012 07:26 AM
Abdul Muqeet
Member
82 Points
428 Posts
logout issue in c#
Jul 04, 2012 12:12 PM|LINK
i m having problem with logout code in asp.net with c#. this logout code should end session, disable browser's back button and and if somebody try to login by paste the url of any user account page, he can't.
plzzz help
i dint use FormAuthentication i just use C# code and redirect to differnt pages through links.... Helppp
hariharakris...
Member
76 Points
32 Posts
Re: logout issue in c#
Jul 04, 2012 12:18 PM|LINK
Hi Abdul Muqeet,
1. Use proper session for maintaining the user session.
2. Use @OutputCache in the aspx pages.
This can bring up your need.
Datta H Shed...
Member
228 Points
104 Posts
Re: logout issue in c#
Jul 04, 2012 12:23 PM|LINK
U need to kill session on sign_out button click. Write the beolw code on signout button click session.RemoveAll(); Session.Abondon(); Response.ClearHeaders(); Response.Redirect("xyz.aspx"); Hope it helps.Abdul Muqeet
Member
82 Points
428 Posts
Re: logout issue in c#
Jul 04, 2012 12:25 PM|LINK
ok i will try this...
i tried this code in web.config file its not redirecting to any page
<authentication mode="Forms">
<forms name=".ASPXFORMSDEMO" loginUrl="login.aspx"
protection="All" path="/" timeout="30" />
</authentication>
<authorization>
<deny users ="?" />
<allow users = "*" />
</authorization>
Abdul Muqeet
Member
82 Points
428 Posts
Re: logout issue in c#
Jul 04, 2012 12:36 PM|LINK
did i write right code for session in ligin page ??? Session["name"] = TxtUserName.Text;
cchidambaram
Member
136 Points
115 Posts
Re: logout issue in c#
Jul 04, 2012 02:30 PM|LINK
Hi,
Use following in body tag or in javascript
and following to remove session
FormAuthentication.SignOut()paulalvin
Member
229 Points
246 Posts
Re: logout issue in c#
Jul 05, 2012 03:55 AM|LINK
Same as my problem before what I did was
protected void LinkButton1_Click(object sender, EventArgs e) { Session.Abandon(); Response.Redirect("logout.aspx"); } protected void LinkButton1_Init(object sender, EventArgs e) { Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1)); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.SetNoStore(); if ((string)Session["QueryString"] == null) { Response.Redirect("login.aspx", true); } }In this case I cannot go back to the page if I already clicked the logout linkbutton
Abdul Muqeet
Member
82 Points
428 Posts
Re: logout issue in c#
Jul 07, 2012 08:07 AM|LINK
i tried this code in logout button its redirecting to same page .. Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1)); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.SetNoStore(); if ((string)Session["QueryString"] == null) { Response.Redirect("login.aspx", true); }Abdul Muqeet
Member
82 Points
428 Posts
Re: logout issue in c#
Jul 08, 2012 07:26 AM|LINK
session.RemoveAll(); Session.Abondon(); Response.ClearHeaders(); Response.Redirect("xyz.aspx"); if (Session[name] == null) { Responce.Redirect(login.aspx); } this work fine