Share via


MobileFormsAuthentication Classe

Definição

Cuidado

The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.

É compatível com dispositivos sem cookie adicionando as informações de autenticação apropriadas às URLs apropriadas. Para obter informações sobre como desenvolver aplicativos móveis ASP.NET, consulte Aplicativos Móveis & Sites com ASP.NET.

public ref class MobileFormsAuthentication
public class MobileFormsAuthentication
[System.Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
public class MobileFormsAuthentication
type MobileFormsAuthentication = class
[<System.Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")>]
type MobileFormsAuthentication = class
Public Class MobileFormsAuthentication
Herança
MobileFormsAuthentication
Atributos

Exemplos

O exemplo de código a seguir mostra uma página login.aspx. A autenticação é validada usando a ValidateUser função . A Membership classe depende de provedores de associação para se comunicar com uma fonte de dados.

<%@ Page Language="C#" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls" 
    Assembly="System.Web.Mobile" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Web.Mobile" %>

<script runat="server">
private void Login_Click(Object sender, EventArgs e)
{
// Perform Authentication check here by using 
// UserEmail.Value and UserPswd.Value.
    if (Membership.ValidateUser(UserEmail.Text, UserPswd.Text))
    {
        // Set the authorization cookie
        FormsAuthentication.SetAuthCookie(UserEmail.Text, false);
        // Redirect from login page
        MobileFormsAuthentication.RedirectFromLoginPage(UserEmail.Text, true);
    }
    else
    {
        // Notify the user
        lblError.Text = "Login invalid. Please check your credentials";
    }
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
    <mobile:form id="form1" runat="server">
        <Mobile:Label runat="server">Enter username</Mobile:Label>
        <Mobile:TextBox id="UserEmail" runat="Server"/>
        <Mobile:Label runat="server">Enter password</Mobile:Label>
        <Mobile:TextBox id="UserPswd" runat="Server"/>
        <Mobile:Command ID="Command1" runat="Server" OnClick="Login_Click"  
            SoftkeyLabel="og">Go</Mobile:Command>
        <Mobile:Label runat="server" id="lblError" />
    </mobile:form>
</body>
</html>
<%@ Page Language="VB" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls" 
    Assembly="System.Web.Mobile" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Web.Mobile" %>

<script runat="server">
    Private Sub Login_Click(ByVal sender As Object, ByVal e As EventArgs)
        ' Perform Authentication check here by using 
        ' UserEmail.Value and UserPswd.Value.
        If (Membership.ValidateUser(UserEmail.Text, UserPswd.Text)) Then
            ' Set the authorization cookie
            FormsAuthentication.SetAuthCookie(UserEmail.Text, False)
            ' Redirect from login page
            MobileFormsAuthentication.RedirectFromLoginPage(UserEmail.Text, True)
        Else
            ' Notify the user
            lblError.Text = "Login invalid. Please check your credentials"
        End If
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
    <mobile:form id="form1" runat="server">
        <Mobile:Label ID="Label1" runat="server">Enter username</Mobile:Label>
        <Mobile:TextBox id="UserEmail" runat="Server"/>
        <Mobile:Label ID="Label2" runat="server">Enter password</Mobile:Label>
        <Mobile:TextBox id="UserPswd" runat="Server"/>
        <Mobile:Command ID="Command1" runat="Server" OnClick="Login_Click"  
            SoftkeyLabel="og">Go</Mobile:Command>
        <Mobile:Label runat="server" id="lblError" />
    </mobile:form>
</body>
</html>

Comentários

Essa classe auxiliar foi projetada para ajudar a escrever sites móveis autenticados. Os objetos de classe fornecem versões compatíveis com dispositivo móvel dos métodos RedirectFromLoginPage de classe ASP.NET FormsAuthentication e SignOut. Para obter mais informações sobre como proteger seu aplicativo Web, consulte Práticas básicas de segurança para aplicativos Web.

Métodos

Equals(Object)
Obsoleto.

Determina se o objeto especificado é igual ao objeto atual.

(Herdado de Object)
GetHashCode()
Obsoleto.

Serve como a função de hash padrão.

(Herdado de Object)
GetType()
Obsoleto.

Obtém o Type da instância atual.

(Herdado de Object)
MemberwiseClone()
Obsoleto.

Cria uma cópia superficial do Object atual.

(Herdado de Object)
RedirectFromLoginPage(String, Boolean)
Obsoleto.

Redireciona um usuário autenticado para a URL solicitada originalmente após o logon. Esta API está obsoleta. Para obter informações sobre como desenvolver aplicativos móveis ASP.NET, consulte Aplicativos Móveis & Sites com ASP.NET.

RedirectFromLoginPage(String, Boolean, String)
Obsoleto.

Redireciona um usuário autenticado para a URL solicitada originalmente após o logon. Esta API está obsoleta. Para obter informações sobre como desenvolver aplicativos móveis ASP.NET, consulte Aplicativos Móveis & Sites com ASP.NET.

SignOut()
Obsoleto.

Chama o método SignOut() e define a propriedade PersistCookielessData como false. Esta API está obsoleta. Para obter informações sobre como desenvolver aplicativos móveis ASP.NET, consulte Aplicativos Móveis & Sites com ASP.NET.

ToString()
Obsoleto.

Retorna uma cadeia de caracteres que representa o objeto atual.

(Herdado de Object)

Aplica-se a

Confira também