MobileFormsAuthentication クラス
アセンブリ: System.Web.Mobile (system.web.mobile.dll 内)
構文
解説
このヘルパー クラスは、認証されたモバイル Web サイトの記述に役立つように設計されています。このクラス オブジェクトは、モバイル デバイスと互換性のある ASP.NET FormsAuthentication クラス メソッド (RedirectFromLoginPage および SignOut) を提供します。Web アプリケーションのセキュリティ保護の詳細については、「Security for ASP.NET Applications」を参照してください。
次のコード例は、login.aspx ページを示しています。認証は、ValidateUser 関数を使用して検証されます。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 > <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 > <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>
System.Web.Mobile.MobileFormsAuthentication
プラットフォーム
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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
- MobileFormsAuthentication クラスのページへのリンク