Flash
Flash is a way to persist a transient value 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:
- The user access the action PasswordManagement.
- A page with some action appears, including a change password form that posts to the ChangePassword action.
- On the ChangePassword action we perform a naive check and, in the event of failure, add an entry to the Flash.
- We send the user back to the PasswordManagement action sending a redirect.
- The view for the PasswordManagement needs to check the flash entry error and show a meaningful error message accordingly.