共用方式為


MobileFormsAuthentication 類別

支援無 Cookie 的裝置,其做法是將適當的驗證 (Authentication) 資訊附加至適當的 URL 之後。

命名空間: System.Web.Mobile
組件: System.Web.Mobile (在 system.web.mobile.dll 中)

語法

'宣告
Public Class MobileFormsAuthentication
'用途
Dim instance As MobileFormsAuthentication
public class MobileFormsAuthentication
public ref class MobileFormsAuthentication
public class MobileFormsAuthentication
public class MobileFormsAuthentication

備註

這個 Helper 類別的設計目的是協助撰寫已驗證的行動網站。類別物件會提供行動裝置相容版本的 ASP.NET FormsAuthentication 類別方法 (Class Method)、RedirectFromLoginPageSignOut。如需保護 Web 應用程式的詳細資訊,請參閱Security for ASP.NET Applications。

範例

下列程式碼範例會顯示 login.aspx 頁面。驗證 (Authentication) 是使用 ValidateUser 函式來進行驗證 (Validate)。Membership 類別需要仰賴成員資格提供者,與資料來源進行通訊。

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

.NET Framework 安全性

繼承階層架構

System.Object
  System.Web.Mobile.MobileFormsAuthentication

執行緒安全

這個型別的所有公用靜態成員 (即 Visual Basic 中的 Shared 成員) 都是安全執行緒。並非所有的執行個體成員均為安全執行緒。

平台

Windows 98、 Windows 2000 SP4、 Windows Millennium Edition、 Windows Server 2003、 Windows XP Media Center Edition、 Windows XP Professional x64 Edition、 Windows XP SP2、 Windows XP Starter Edition

.NET Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱系統需求一節的內容。

版本資訊

.NET Framework

支援版本:2.0、1.1

請參閱

參考

MobileFormsAuthentication 成員
System.Web.Mobile 命名空間
RedirectFromLoginPage
FormsAuthentication

其他資源

Security for ASP.NET Applications
ASP.NET 驗證
成員資格簡介