Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'll explain a bit the following code and what lefts for you to do.</p> <p>At the first request off this page, the code checks if the LocalTime is not already stored in Session and if not it will write a form element, a hidden input and a javascript which will post that form with the local time. The response ends, so your report won't get the chance to be generated.</p> <p>This submit will immediately create a POST request with the localTime set, then ASP .Net stores this POST value into the Session.</p> <p>I also added a 302 redirect (Response.Redirect) to the original page, because of the usability. The User made initially a GET request, not a POST, so if he/she wants to refresh the page, the browser will reiterate the last action, which was that form.submit() and not the GET request.</p> <p>You have now the local time. But you don't have to read it at every request since it can be compared to the UTC time, then with the server's time.</p> <p><em>edit:</em> You need to parse the UTC time into a DateTime, but probably it's easy to find the format, though might depend on the user's culture (not sure about this statement).</p> <pre><code>public ReportPage() { this.Init += (o, e) =&gt; { // if the local time is not saved yet in Session and the request has not posted the localTime if (Session["localTime"] == null &amp;&amp; String.IsNullOrEmpty(Request.Params["localTime"])) { // then clear the content and write some html, a javascript code which submits the local time Response.ClearContent(); Response.Write(@"&lt;form id='local' method='post' name='local'&gt; &lt;input type='hidden' id='localTime' name='localTime' /&gt; &lt;script type='text/javascript'&gt; document.getElementById('localTime').value = new Date(); document.getElementById('local').submit(); &lt;/script&gt; &lt;/form&gt;"); // Response.Flush(); // end the response so PageLoad, PagePreRender etc won't be executed Response.End(); } else { // if the request contains the localtime, then save it in Session if (Request.Params["localTime"] != null) { Session["localTime"] = Request.Params["localTime"]; // and redirect back to the original url Response.Redirect(Request.RawUrl); } } }; } </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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