Share via


RedirectFromLoginPage Method

Redirect an authenticated user back to the originally requested URL.

public static void RedirectFromLoginPage( 
   string username, 
   bool createPersistentCookie
)
public static void RedirectFromLoginPage( 
   string username, 
   bool createPersistentCookie, 
   string cookiePath
)

Parameters

  • username
    Name of the user for cookie authentication purposes. This does not need to map to an account name and is used by URL Authorization.
  • createPersistentCookie
    Specifies whether or not a durable cookie (one that is session based or outlasts the session) must be issued.
  • cookiePath
    Returns the configured cookie path used for the current application.

Remarks

The methods create an encrypted string from the authentication cookie and append it to the redirecting URL of the originating request. A client-side redirect is then issued for that URL. This can be used to work around the limitations of certain mobile devices that either do not support cookies or support cookies that are too small for storing authentication information in a secure manner.

Example

The following example demonstrates how to use the RedirectFromLoginPage method to send the authenticated user back to the URL that was originally requested.

[Visual Basic]

'Web.config
<authentication mode="Forms">
   <forms name=".COOKIEDEMO" loginUrl="login.aspx" protection="All"
   timeout="60" path="/"> 
      </forms>
</authentication>

'Login.aspx

<Script language="vb" runat="server">

Sub Login_Click(sender As Object, e As EventArgs)
   ' Perform Authentication check here by using UserEmail.Text and UserPswd.Value.
   If True Then
      MobileFormsAuthentication.RedirectFromLoginPage(UserEmail.Text, False)
   End If
End Sub

</Script>

<Mobile:Form id="formA" runat=server Paginate="True">
   <Mobile:Label>Enter username</Mobile:Label>
   <Mobile:TextBox id="UserEmail" runat="Server"/>
   <Mobile:Label>Enter password</Mobile:Label>
   <Mobile:TextBox id="UserPswd" runat="Server"/>
   <Mobile:Command runat="Server" OnClick="Login_Click"
       SoftkeyLabel="go">Go</Mobile:Command>
</Mobile:Form>

[C#]

// Web.config
<authentication mode="Forms">
   <forms name=".COOKIEDEMO" loginUrl="login.aspx" protection="All"
   timeout="60" path="/"> 
      </forms>
</authentication>
// Login.aspx


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

<Mobile:Form id="formA" runat=server Paginate="True">
   <Mobile:Label>Enter username</Mobile:Label>
   <Mobile:TextBox id="UserEmail" runat="Server"/>
   <Mobile:Label>Enter password</Mobile:Label>
   <Mobile:TextBox id="UserPswd" runat="Server"/>
   <Mobile:Command runat="Server" OnClick="Login_Click"
       SoftkeyLabel="go">Go</Mobile:Command>
</Mobile:Form>

See Also

Applies to: MobileFormsAuthentication Class