Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A solution to that problem can be implemented by the following:</p> <pre><code>public static class CommonHelper { public static bool SiteGuard { get { if(HttpContext.Current.Session["SiteGuard"] == null) return true; return (bool)HttpContext.Current.Session["SiteGuard"]; } set { HttpContext.Current.Session["SiteGuard"] = value; } } } public partial class TestPage : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if(!Page.IsPostBack) { bool go = false; for(int i = 0; i &lt; 50; i++) // wait for the service to work (5 secs max) { if(CommonHelper.SiteGuard) { go = true; break; } Thread.Sleep(100); } if(!go) Response.Redirect("Login.aspx"); SiteGuard = false; // from now on, nobody can visit your site } // Now as long as Page.IsPostBack is true you are in a good shape } } </code></pre> <p>Add an asmx web service (or any other type of services you think is suitable) to your root project and add the following method to it:</p> <pre><code> [WebMethod(EnableSession = true)] public void FreeSiteGuard() { HttpContext.Current.Session["SiteGuard"] = null; } </code></pre> <p>In the master page, or on every page add the following javascript:</p> <pre><code>&lt;script type="text/javascript"&gt; window.onbeforeunload = function (e) { e = e || window.event; if (e) { // Invoke web service YourProject.YourWebServiceName.FreeSiteGuard(); } }; &lt;/script&gt; </code></pre> <p>Note that your site response time gets affected by the speed of the web service.</p>
 

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