Home

Castle Stronghold

Flash

Flash is a way to persist transient values between requests. It is useful when you perform some process and issue a redirect. On the redirect target you can check the Flash for a status code, error message or something equivalent. For example:


using Castle.MonoRail.Framework;

public class AdminController : Controller
{
    public void PasswordManagement()
    {
    }

    public void ChangePassword()
    {
        String passwd = Params["password"];
    
        if (passwd.Length < 6)
        {
            Flash["error"] = "Password too weak, operation aborted";
        }
        else
        {
            // Change password
        }
    
        RedirectToAction("PasswordManagement");
    }
}

The flow might be not clear in the example above. So, let's see what exactly happens:

  1. The user accesses the action PasswordManagement.
  2. The view for PasswordManagement appears, including a change password form that posts to the ChangePassword action.
  3. On the ChangePassword action we perform a naive check and, in the event of failure, add an entry to the Flash.
  4. We send the user back to the PasswordManagement action sending a redirect.
  5. The view for the PasswordManagement needs to check the Flash entry "error" and show a meaningful error message accordingly.

Google
Search WWW Search castleproject.org