c# - How to logout in asp.net using a html button? -


i've created masterpage there button named sign out. how can use button in order sign out or logout current login session.

here button code:

<a href="#" class="btn btn-default btn-flat">sign out</a> 

any appreciated!

use logout code.

<a href="logout.aspx" class="btn btn-default btn-flat">sign out</a> 

logout.aspx

<form id="form1" runat="server">     <asp:label id="label1" text="loggin out please wait" runat="server" />     <asp:scriptmanager id="scriptmanager1" runat="server">     </asp:scriptmanager>     <div>         <asp:updatepanel id="updatepanel1" runat="server">             <contenttemplate>                 <asp:timer id="timer1" runat="server" interval="1000" ontick="timer1_tick">                 </asp:timer>             </contenttemplate>         </asp:updatepanel>     </div>     </form> 

logout.aspx.cs

protected void timer1_tick(object sender, eventargs e)     {         session.clear();         session.abandon();         response.cache.setexpires(datetime.utcnow.addminutes(-1));         response.cache.setcacheability(httpcacheability.nocache);         response.cache.setnostore();          try         {             session.abandon();             formsauthentication.signout();             response.cache.setcacheability(httpcacheability.nocache);             response.buffer = true;             response.expiresabsolute = datetime.now.adddays(-1d);             response.expires = -1000;             response.cachecontrol = "no-cache";             //response.redirect("login.aspx", true);         }         catch (exception ex)         {             response.write(ex.message);         }         response.redirect("~/login.aspx");     } 

Comments