Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

FormsAuthentication.RedirectToLoginPage Method

Redirects the browser to the login URL.

This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.

  Name Description
Public method Static member RedirectToLoginPage() Redirects the browser to the login URL.
Public method Static member RedirectToLoginPage(String) Redirects the browser to the login URL with the specified query string.
Top

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.

Unlike the HttpResponse.Redirect method, this method does not end the request by calling HttpResponse.End. This means that code that follows the RedirectToLoginPage method call will run.

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>
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.