Share via


MobileFormsAuthentication Class

Supports cookieless devices by appending appropriate authentication information to the appropriate URLs.

public class System.Web.Mobile.MobileFormsAuthentication : System.Object

Remarks

This helper class is designed to assist with writing authenticated mobile Web sites. The class objects provide mobile device-compatible versions of the ASP.NET FormsAuthentication class methods, RedirectFromLoginPage and SignOut. See Security Considerations for ASP.NET Web Applications for further information on securing your Web application.

Example

The following code example shows the login.aspx page. There is no specific authentication check performed in this example.

<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Web.Mobile" %>
<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" 
      Language="c#" %>

<script language="c#" runat=server>
void Login_Click(Object sender, EventArgs e)
{
// Perform Authentication check here by using UserEmail.Value and
// UserPswd.Value.
   if(IsAuthenticated(UserEmail.Text, UserPswd.Text))
   {
      FormsAuthentication.SetAuthCookie(UserEmail.Text, false);
      MobileFormsAuthentication.RedirectFromLoginPage(UserEmail.Text,true);
   }
   else
   {
      lblError.Text = "Please check your credentials";
   }
}

bool IsAuthenticated(String user, String password)
{
   if(FormsAuthentication.Authenticate(user, password))
      return true;
   else
      return false;
}

</script>

<Mobile:Form id="formA" runat=server Paginate="True">
   <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 runat="Server" OnClick="Login_Click"  
      SoftkeyLabel="og">Go</Mobile:Command>
   <Mobile:Label runat="server" id="lblError" />
</Mobile:Form>

Requirements

Namespace: System.Web.Mobile

Assembly: System.Web.Mobile

See Also

RedirectFromLoginPage Method