FormsAuthentication.RedirectToLoginPage Method ()
.NET Framework (current version)
Redirects the browser to the login URL.
Assembly: System.Web (in System.Web.dll)
The following code example clears the forms-authentication cookie using the SignOut method and redirects the user to the login page using the RedirectToLoginPage method.
<%@ Page Language="C#" %> <%@ Import Namespace="System.Web.Security" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> public void LoginLink_OnClick(object sender, EventArgs args) { FormsAuthentication.SignOut(); FormsAuthentication.RedirectToLoginPage(); } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>ASP.NET Example</title> </head> <body> <form id="form1" runat="server"> Welcome <b><%=User.Identity.Name%></b>. Not <b><%=User.Identity.Name%></b>? Click <asp:LinkButton id="LoginLink" Text="here" OnClick="LoginLink_OnClick" runat="server" /> to sign in. <!-- Page Contents --> </form> </body> </html>
.NET Framework
Available since 2.0
Available since 2.0
Show: