紀錄系統登出登入時間

無MasterPage的寫法
——————————————————————————-
<script type=”text/javascript” language=”javascript”>
window.onunload = CloseWindows;
function CloseWindows() {
//按下X關閉
if (event.clientY < 0) {
try {
var xmlhttp = new ActiveXObject(“Microsoft.XMLHTTP”);
//使用者自行關閉視窗時
xmlhttp.open(“POST”,”CloseWindows.aspx”, false);
xmlhttp.send();
return true;
}
catch (e) {
alert(‘close windows error message:’ + e.message);
}
}
}
</script>

=================================================

MasterPage的寫法
——————————————————————————
MasterPage.aspx
<script type=”text/javascript” language=”javascript”>
window.onunload = CloseWindows;
function CloseWindows() {
//按下X關閉
if (event.clientY < 0) {
try {
var xmlhttp = new ActiveXObject(“Microsoft.XMLHTTP”);
//使用者自行關閉視窗時
var url = document.getElementById(“CloseWeb_URL”).value;
xmlhttp.open(“POST”, url, false);
xmlhttp.send();
return true;
}
catch (e) {
alert(‘close windows error message:’ + e.message);
}
}
}
</script>
<asp:HiddenField ID=”CloseWeb_URL” runat=”server” />
———————————————————————————

MasterPage.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
CloseWeb_URL.Value = GetCloseWeb();
}
}
private string GetCloseWeb()
{
string Path = Request.PhysicalPath.Replace(Request.PhysicalApplicationPath, “”).Replace(@”\”, @”/”);
Path = Request.Url.ToString().Replace(Path, “”) + “CloseWindows.aspx?url=” + Request.RawUrl;
//後面的 Request.RawUrl想抓到是在哪個頁面關閉了視窗
return Path;
}

by mhchen15 on 23 11 月, 2012 in ASP.NET C#, 程式

There are no comments.

Name*: Website: E-Mail*:
XHTML: You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>