Subscribe

RSS Feed (xml)

Creating a Simple Forms Authentication Logout Page

Place a LinkButton control on the page and assign it the text of


Logout. Place a Literal


control on your page and title it message.This will be populated with a message telling


the users they have logged out and including the code to redirect them to another page.



The ASPX page is as follows:



<p align="center"><asp:LinkButton ID="Logout" Runat="server" OnClick="Logout_




Click">Logout</asp:LinkButton></p>


<p align="center"><asp:Literal ID="Message" Runat="server" /></p>


In <script runat="server" /> block or codebehind:


private void Logout_Click(object sender, System.EventArgs e)


{


System.Web.Security.FormsAuthentication.SignOut();


Message.Text="You have been logged out.";


Message.Text+="<meta http-equiv=\"Refresh\"


content=\"3;URL=http://aspalliance.com\" />";


}


Comments


On the Logout button Click event, do the following:


n Call System.Web.Security.FormsAuthentication.SignOut().This method


forces a log out by removing the authentication ticket and session cookies.


n Add text to the Message literal control to let the users know they have been


logged out.


n Add a Meta tag to the Message literal control to redirect the users to another page.


If you want to send the users back to the login page, you can redirect them to any


page in the application. Forms authentication will force the users to log in first


(assuming the page requires an authenticated user).




Technorati :

No comments:

Archives

Variety in the Web World