RedirectToLoginPage Method
Collapse the table of content
Expand the table of content

FormsAuthentication.RedirectToLoginPage Method ()


Redirects the browser to the login URL.

Namespace:   System.Web.Security
Assembly:  System.Web (in System.Web.dll)

public static void RedirectToLoginPage()

The RedirectToLoginPage method redirects the browser to the LoginUrl.

The RedirectToLoginPage method does not clear the forms-authentication cookie. You can use the RedirectToLoginPage method in conjunction with the SignOut method to log one user out and allow a different user to log in.

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"
<script runat="server">

public void LoginLink_OnClick(object sender, EventArgs args)

<html xmlns="" >
<head runat="server">
    <title>ASP.NET Example</title>

<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 -->



.NET Framework
Available since 2.0
Return to top
© 2015 Microsoft