FormsAuthentication.RedirectFromLoginPage Método

Definição

Redireciona um usuário autenticado de volta para a URL solicitada originalmente ou a URL padrão.Redirects an authenticated user back to the originally requested URL or the default URL.

Sobrecargas

RedirectFromLoginPage(String, Boolean)

Redireciona um usuário autenticado de volta para a URL solicitada originalmente ou a URL padrão.Redirects an authenticated user back to the originally requested URL or the default URL.

RedirectFromLoginPage(String, Boolean, String)

Redireciona um usuário autenticado de volta para a URL solicitada originalmente ou para a URL padrão usando o caminho do cookie especificado para o cookie de autenticação de formulários.Redirects an authenticated user back to the originally requested URL or the default URL using the specified cookie path for the forms-authentication cookie.

RedirectFromLoginPage(String, Boolean)

Redireciona um usuário autenticado de volta para a URL solicitada originalmente ou a URL padrão.Redirects an authenticated user back to the originally requested URL or the default URL.

public:
 static void RedirectFromLoginPage(System::String ^ userName, bool createPersistentCookie);
public static void RedirectFromLoginPage (string userName, bool createPersistentCookie);
static member RedirectFromLoginPage : string * bool -> unit
Public Shared Sub RedirectFromLoginPage (userName As String, createPersistentCookie As Boolean)

Parâmetros

userName
String

O nome de usuário autenticado.The authenticated user name.

createPersistentCookie
Boolean

true para criar um cookie durável (um que seja salvo entre as sessões do navegador); caso contrário, false.true to create a durable cookie (one that is saved across browser sessions); otherwise, false.

Exceções

A URL de retorno especificada na cadeia de caracteres de consulta contém um protocolo diferente de HTTP: ou HTTPS:.The return URL specified in the query string contains a protocol other than HTTP: or HTTPS:.

Exemplos

O exemplo de código a seguir redireciona os usuários validados para a URL solicitada originalmente ou para o DefaultUrl .The following code example redirects validated users to either the originally requested URL or the DefaultUrl. O exemplo de código usa associação ASP.NET para validar usuários.The code example uses ASP.NET membership to validate users. Para obter mais informações sobre associação do ASP.NET, consulte Gerenciando usuários usando a associação.For more information about ASP.NET membership, see Managing Users by Using Membership.

Importante

Este exemplo contém uma caixa de texto que aceita a entrada do usuário, que é uma possível ameaça à segurança.This example contains a text box that accepts user input, which is a potential security threat. Por padrão, as páginas da Web do ASP.NET validam que a entrada do usuário não inclui elementos de script ou HTML.By default, ASP.NET Web pages validate that user input does not include script or HTML elements. Para obter mais informações, consulte Visão geral de explorações de script.For more information, see Script Exploits Overview.

<%@ 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 Login_OnClick(object sender, EventArgs args)
{
   if (Membership.ValidateUser(UsernameTextbox.Text, PasswordTextbox.Text))
      FormsAuthentication.RedirectFromLoginPage(UsernameTextbox.Text, NotPublicCheckBox.Checked);
   else
     Msg.Text = "Login failed. Please check your user name and password and try again.";
}


</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
  <title>Login</title>
</head>
<body>

<form id="form1" runat="server">
  <h3>Login</h3>

  <asp:Label id="Msg" ForeColor="maroon" runat="server" /><br />

  Username: <asp:Textbox id="UsernameTextbox" runat="server" /><br />
  Password: <asp:Textbox id="PasswordTextbox" runat="server" TextMode="Password" /><br />
 
  <asp:Button id="LoginButton" Text="Login" OnClick="Login_OnClick" runat="server" />
  <asp:CheckBox id="NotPublicCheckBox" runat="server" /> 
  Check here if this is <span style="text-decoration:underline">not</span> a public computer.

</form>

</body>
</html>
<%@ Page Language="VB" %>
<%@ 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 Sub Login_OnClick(sender As Object, args As  EventArgs)

   If (Membership.ValidateUser(UsernameTextbox.Text, PasswordTextbox.Text)) Then
      FormsAuthentication.RedirectFromLoginPage(UsernameTextbox.Text, NotPublicCheckBox.Checked)
   Else
     Msg.Text = "Login failed. Please check your user name and password and try again."
   End If

End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
  <title>Login</title>
</head>
<body>

<form id="form1" runat="server">
  <h3>Login</h3>

  <asp:Label id="Msg" ForeColor="maroon" runat="server" /><br />

  Username: <asp:Textbox id="UsernameTextbox" runat="server" /><br />
  Password: <asp:Textbox id="PasswordTextbox" runat="server" TextMode="Password" /><br />
 
  <asp:Button id="LoginButton" Text="Login" OnClick="Login_OnClick" runat="server" />
  <asp:CheckBox id="NotPublicCheckBox" runat="server" /> 
  Check here if this is <span style="text-decoration:underline">not</span> a public computer.

</form>

</body>
</html>

Comentários

O RedirectFromLoginPage método redireciona para a URL especificada na cadeia de caracteres de consulta usando o ReturnURL nome da variável.The RedirectFromLoginPage method redirects to the URL specified in the query string using the ReturnURL variable name. Por exemplo, na URL http://www.contoso.com/login.aspx?ReturnUrl=caller.aspx , o RedirectFromLoginPage método redireciona para a URL de retorno caller.aspx .For example, in the URL http://www.contoso.com/login.aspx?ReturnUrl=caller.aspx, the RedirectFromLoginPage method redirects to the return URL caller.aspx. Se a ReturnURL variável não existir, o RedirectFromLoginPage método redirecionará para a URL na DefaultUrl propriedade.If the ReturnURL variable does not exist, the RedirectFromLoginPage method redirects to the URL in the DefaultUrl property.

O ASP.NET adiciona automaticamente a URL de retorno quando o navegador é redirecionado para a página de logon.ASP.NET automatically adds the return URL when the browser is redirected to the login page.

Por padrão, a ReturnUrl variável deve se referir a uma página dentro do aplicativo atual.By default, the ReturnUrl variable must refer to a page within the current application. Se ReturnUrl o se referir a uma página em um aplicativo diferente ou em um servidor diferente, os RedirectFromLoginPage métodos redirecionarão para a URL na DefaultUrl propriedade.If ReturnUrl refers to a page in a different application or on a different server, the RedirectFromLoginPage methods redirects to the URL in the DefaultUrl property. Se você quiser permitir redirecionamentos para uma página fora do aplicativo atual, você deve definir a EnableCrossAppRedirects propriedade como true usando o enableCrossAppRedirects atributo do elemento de configuração de formulários .If you want to allow redirects to a page outside the current application, you must set the EnableCrossAppRedirects property to true using the enableCrossAppRedirects attribute of the forms configuration element.

Importante

Definir a EnableCrossAppRedirects propriedade como true para permitir redirecionamentos entre aplicativos é uma possível ameaça à segurança.Setting the EnableCrossAppRedirects property to true to allow cross-application redirects is a potential security threat. Para obter mais informações, consulte a propriedade EnableCrossAppRedirects.For more information, see the EnableCrossAppRedirects property.

Se a CookiesSupported propriedade for true , e a ReturnUrl variável estiver dentro do aplicativo atual ou a EnableCrossAppRedirects propriedade for true , o RedirectFromLoginPage método emitirá um tíquete de autenticação e o colocará no cookie padrão usando o SetAuthCookie método.If the CookiesSupported property is true, and either the ReturnUrl variable is within the current application or the EnableCrossAppRedirects property is true, then the RedirectFromLoginPage method issues an authentication ticket and places it in the default cookie using the SetAuthCookie method.

Se CookiesSupported for false e o caminho de redirecionamento for para uma URL no aplicativo atual, o tíquete será emitido como parte da URL de redirecionamento.If CookiesSupported is false and the redirect path is to a URL in the current application, the ticket is issued as part of the redirect URL. Se CookiesSupported for false , EnableCrossAppRedirects for true , e a URL de redirecionamento não fizer referência a uma página dentro do aplicativo atual, o RedirectFromLoginPage método emitirá um tíquete de autenticação e o colocará na QueryString propriedade.If CookiesSupported is false, EnableCrossAppRedirects is true, and the redirect URL does not refer to a page within the current application, the RedirectFromLoginPage method issues an authentication ticket and places it in the QueryString property.

Aplica-se a

RedirectFromLoginPage(String, Boolean, String)

Redireciona um usuário autenticado de volta para a URL solicitada originalmente ou para a URL padrão usando o caminho do cookie especificado para o cookie de autenticação de formulários.Redirects an authenticated user back to the originally requested URL or the default URL using the specified cookie path for the forms-authentication cookie.

public:
 static void RedirectFromLoginPage(System::String ^ userName, bool createPersistentCookie, System::String ^ strCookiePath);
public static void RedirectFromLoginPage (string userName, bool createPersistentCookie, string strCookiePath);
static member RedirectFromLoginPage : string * bool * string -> unit
Public Shared Sub RedirectFromLoginPage (userName As String, createPersistentCookie As Boolean, strCookiePath As String)

Parâmetros

userName
String

O nome de usuário autenticado.The authenticated user name.

createPersistentCookie
Boolean

true para criar um cookie durável (um que seja salvo entre as sessões do navegador); caso contrário, false.true to create a durable cookie (one that is saved across browser sessions); otherwise, false.

strCookiePath
String

O caminho do cookie para que o tíquete de autenticação de formulários.The cookie path for the forms-authentication ticket.

Exceções

A URL de retorno especificada na cadeia de caracteres de consulta contém um protocolo diferente de HTTP: ou HTTPS:.The return URL specified in the query string contains a protocol other than HTTP: or HTTPS:.

Comentários

O RedirectFromLoginPage método redireciona para a URL de retorno especificada na cadeia de caracteres de consulta usando o ReturnURL nome da variável.The RedirectFromLoginPage method redirects to the return URL specified in the query string using the ReturnURL variable name. Por exemplo, na URL http://www.contoso.com/login.aspx?ReturnUrl=caller.aspx , o RedirectFromLoginPage método redireciona para a URL de retorno caller.aspx .For example, in the URL http://www.contoso.com/login.aspx?ReturnUrl=caller.aspx, the RedirectFromLoginPage method redirects to the return URL caller.aspx. Se a ReturnURL variável não existir, o RedirectFromLoginPage método redirecionará para a URL na DefaultUrl propriedade.If the ReturnURL variable does not exist, the RedirectFromLoginPage method redirects to the URL in the DefaultUrl property.

O ASP.NET adiciona automaticamente a URL de retorno quando o navegador é redirecionado para a página de logon.ASP.NET automatically adds the return URL when the browser is redirected to the login page.

Por padrão, a ReturnUrl variável deve se referir a uma página dentro do aplicativo atual.By default, the ReturnUrl variable must refer to a page within the current application. Se ReturnUrl o se referir a uma página em um aplicativo diferente ou em um servidor diferente, o RedirectFromLoginPage método redirecionará para a URL na DefaultUrl propriedade.If ReturnUrl refers to a page in a different application or on a different server, the RedirectFromLoginPage method redirects to the URL in the DefaultUrl property. Se você quiser permitir redirecionamentos para uma página fora do aplicativo atual, você deve definir a EnableCrossAppRedirects propriedade como true usando o enableCrossAppRedirects atributo do elemento de configuração de formulários .If you want to allow redirects to a page outside the current application, you must set the EnableCrossAppRedirects property to true using the enableCrossAppRedirects attribute of the forms configuration element.

Importante

Definir a EnableCrossAppRedirects propriedade como true para permitir redirecionamentos entre aplicativos é uma possível ameaça à segurança.Setting the EnableCrossAppRedirects property to true to allow cross-application redirects is a potential security threat. Para obter mais informações, consulte a propriedade EnableCrossAppRedirects.For more information, see the EnableCrossAppRedirects property.

Se a CookiesSupported propriedade for true , e a ReturnUrl variável estiver dentro do aplicativo atual ou a EnableCrossAppRedirects propriedade for true , o RedirectFromLoginPage método emitirá um tíquete de autenticação e o colocará no cookie especificado pelo strCookiePath parâmetro usando o SetAuthCookie método.If the CookiesSupported property is true, and either the ReturnUrl variable is within the current application or the EnableCrossAppRedirects property is true, then the RedirectFromLoginPage method issues an authentication ticket and places it in the cookie specified by the strCookiePath parameter using the SetAuthCookie method.

Se CookiesSupported for false e o caminho de redirecionamento for para uma URL no aplicativo atual, o tíquete será emitido como parte da URL de redirecionamento.If CookiesSupported is false and the redirect path is to a URL in the current application, the ticket is issued as part of the redirect URL. Se CookiesSupported for false , EnableCrossAppRedirects for true , e a URL de redirecionamento não fizer referência a uma página dentro do aplicativo atual, o RedirectFromLoginPage método emitirá um tíquete de autenticação e o colocará na QueryString propriedade.If CookiesSupported is false, EnableCrossAppRedirects is true, and the redirect URL does not refer to a page within the current application, the RedirectFromLoginPage method issues an authentication ticket and places it in the QueryString property.

Aplica-se a