สอบถามเรื่องการทำ session timeout ครับ รบกวนช่วยดูให้หน่อยครับ
คือผมนำโค๊ดนี้ มาใช้งานครับ จากเว็ปนอก เพื่อกำหนด session ระยะเวลา login แต่โค๊ดนี้ผมเองไม่สามารถไล่ให้มาใช้กับระบบผมได้ครับ รบกวนช่วยไล่ให้ทีครับ โดยผมต้องการให้แสดง user login แผนกและรายละเอียดจากโค๊ดของผมเหมือนเดิม แต่เพิ่ท session time out ครับ
โค๊ดที่ผมได้มา
Code (VB.NET)
Response.Cache.SetCacheability(HttpCacheability.NoCache)
If IsPostBack = False Then
Session("Reset") = True
Dim config As Configuration = WebConfigurationManager.OpenWebConfiguration("~/Web.Config")
Dim section As SessionStateSection = DirectCast(config.GetSection("system.web/sessionState"), SessionStateSection)
Dim timeout As Integer = CInt(section.Timeout.TotalMinutes) * 1000 * 60
ClientScript.RegisterStartupScript(Me.GetType(), "SessionAlert", "SessionExpireAlert(" & timeout & ");", True)
<script type="text/javascript">
function SessionExpireAlert(timeout) {
var seconds = timeout / 1000;
document.getElementsByName("secondsIdle").innerHTML = seconds;
document.getElementsByName("seconds").innerHTML = seconds;
setInterval(function () {
seconds--;
document.getElementById("seconds").innerHTML = seconds;
document.getElementById("secondsIdle").innerHTML = seconds;
}, 1000);
setTimeout(function () {
//Show Popup before 20 seconds of timeout.
$find("mpeTimeout").show();
}, timeout - 20 * 1000);
setTimeout(function () {
window.location = "Login.aspx";
}, timeout);
};
function ResetSession() {
//Redirect to refresh Session.
window.location = window.location.href;
}
</script>
<h5>Session Idle: <span id="secondsIdle"></span> seconds.</h5>
<asp:LinkButton ID="lnkFake" runat="server" />
<asp:ModalPopupExtender ID="mpeTimeout" BehaviorID ="mpeTimeout" runat="server" PopupControlID="pnlPopup" TargetControlID="lnkFake"
OkControlID="btnYes" CancelControlID="btnNo" BackgroundCssClass="modalBackground" OnOkScript = "ResetSession()">
</asp:ModalPopupExtender>
<asp:Panel ID="pnlPopup" runat="server" CssClass="modalPopup" Style="display: none">
<div class="header">
Session Expiring!
</div>
<div class="body">
Your Session will expire in <span id="seconds"></span> seconds.<br />
Do you want to reset?
</div>
<div class="footer" align="right">
<asp:Button ID="btnYes" runat="server" Text="Yes" CssClass="yes" />
<asp:Button ID="btnNo" runat="server" Text="No" CssClass="no" />
</div>
</asp:Panel>
อันนี้ของผมเองครับ
Code (VB.NET)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-GB")
Response.Cache.SetCacheability(HttpCacheability.NoCache)
If Session("USERID") <> Nothing Then
If IsPostBack = False Then
Dim V As String = Session("view")
Dim P As String = Session("Postpone")
Dim A As String = Session("Approve")
Dim SP As String = Session("SP")
If Session("view") = Nothing And Session("Postpone") = Nothing And Session("Approve") = Nothing Then
Panel13.Visible = False
Panel10.Visible = True
ImbEdit.Visible = True
imbNew.Visible = True
ImbEditship.Visible = False
Panel5.Visible = False
Panel3.Visible = False
Panel4.Visible = False
Panel6.Visible = False
Panel7.Visible = False
Panel8.Visible = False
Panel9.Visible = False
Panel11.Visible = False
Panel12.Visible = False
btnRelease.Visible = False
btnADD.Visible = False
btnSave.Visible = False
Imagenew.Visible = False
lblAD_ADDR.Visible = False
lblAD_CITY.Visible = False
lblAD_LINE1.Visible = False
lblAD_LINE3.Visible = False
lblAD_LINE4.Visible = False
lblAD_LINE2Bill.Visible = False
lblAD_LINE3Bill.Visible = False
lblAD_NAME.Visible = False
lblAD_COUNTRY.Visible = False
lblad_phone.Visible = False
lblad_phone0.Visible = False
lblAD_ADDR0.Visible = False
lblAD_CITY0.Visible = False
lblAD_LINE2.Visible = False
lblAD_NAME0.Visible = False
lblAD_COUNTRY0.Visible = False
lblAD_STATE.Visible = False
lblAD_ZIP0.Visible = False
lblAD_ZIP.Visible = False
lblAD_STATE0.Visible = False
btnReturn.Visible = False
cbPackage.Items.Insert(0, New ListItem("--select--", ""))
cbPackage.SelectedValue = cbPackage.Items(0).Value
cbApprove.Visible = False
Dim dtc As DataSet
dtc = gcurren()
With Me.cbCurr
.Items.Clear()
.DataSource = dtc
.DataTextField = "cu_curr"
.DataValueField = "cu_curr"
.DataBind()
End With
End If
If A = "Approve" Then
If SP = "SP" Then
Dim wf_doc As String = Session("wf_doc")
ViewSaleInvoid(sender, e)
Panel10.Visible = True
ImbEdit.Visible = False
imbNew.Visible = False
ImbEditship.Visible = True
btnReturn.Visible = True
Panel6.Visible = False
lblappove.Visible = False
cbApprove.Visible = False
btncancle.Visible = False
Label109.Visible = False
Else
Dim wf_doc As String = Session("wf_doc")
ViewSaleInvoid(sender, e)
Panel10.Visible = True
ImbEdit.Visible = False
imbNew.Visible = False
ImbEditship.Visible = False
btnReturn.Visible = True
End If
End If
If P = "Postpone" Then
ImbEditship.Visible = False
Dim Doc As String = Session("wf_doc")
ViewSaleInvoid(sender, e)
btnReturn.Visible = True
End If
End If
If rdoReyes.Checked = True Then
lblBOILocal.Text = "ใบขนสุทธินำกลับ"
lblBOIImport.Text = "ใบขนสุทธินำกลับ"
lblNONBOILocal.Text = "ใบขนปากระวาง"
lblTexedImport.Text = "(นำเข้าโดยเสียภาษี)"
ElseIf rdoReno.Checked = True Then
lblBOILocal.Text = ""
lblNONBOILocal.Text = "ใบขนปากระวาง"
lblBOIImport.Text = ""
lblTexedImport.Text = "(นำเข้าโดยเสียภาษี)"
End If
amountfooter()
Else
Response.Redirect("Login.aspx")
End If
End Sub
Tag : .NET, JavaScript, Ajax, VS 2008 (.NET 3.x), VS 2010 (.NET 4.x)
Date :
2017-07-24 08:14:08
By :
bankguszo
View :
1343
Reply :
3
เค้าทำที่หน้า ASPX ครับ เข้าใจว่าน่าจะใช้ JavaScript ในการเช็คจากเวลาที่ TimeOut ครับ
Date :
2017-07-24 17:08:27
By :
mr.win
ทำได้แล้วครับ ตอนแรกติดปัญหา java scrip error (Microsoft JScript runtime error: Unable to set value of the property 'innerHTML': object is null or undefined) ตอนนี้ผมแก้ไขได้แล้วครับ
ประวัติการแก้ไข 2017-07-25 10:20:30
Date :
2017-07-25 10:19:14
By :
bankguszo
Load balance : Server 00