Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I usually create a holding page mechanism which will look to see if a particular cookie has been set. In the past I've done this by creating a HttpModule, but more recently I've used an ActionFilter so I can fine tune which controllers I want the lock to go on. Once the cookie has been set you can use your site as normal.</p> <pre><code>public class CookieProtectAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { if (WebSettings.HoldingPageOn) //Helper to check web.config if holding page is active { //Make sure you don't go into an infinite loop - ideally the holding page controller wont have the cookie protect action filter if (!filterContext.HttpContext.Request.RawUrl.ToLower().Contains("holding")) { var accessCookie = filterContext.HttpContext.Request.Cookies["AllowAccess"]; if (accessCookie == null) { filterContext.Result = new RedirectToRouteResult("Holding", null, false); filterContext.Result.ExecuteResult(filterContext); } } } base.OnActionExecuting(filterContext); } } </code></pre> <p>Then to set the cookie I would wire up a particular route to an action method such as ...</p> <pre><code>[HttpGet] public ActionResult HoldingAccess(string id) { if (id.NullSafe() == "yourpassword") { Response.Cookies.Add(new HttpCookie("AllowAccess") {Expires = DateTime.Now.AddDays(7)}); return RedirectToRoute("Home"); } return HttpNotFound(); } </code></pre> <p>So the route you setup to set the cookie could be anything, and in the example above you can set a hardcoded "password" - i.e. /OpenSesame/yourpassword route would set the cookie</p> <p>It's simple code, but it seems to work well.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload