简体   繁体   中英

How to fix “MasterPage is undefined” in javascript function?

I am currently supporting a web-based app in asp.net vb. This part of code below is for checking the session and automatically logs off the user after the expiration of session. Also, I have a security window that pops up upon the successful log in and also logs off the user whenever this pop up window is refreshed or closed.

The problem is I am having an error saying "MasterPage is Undefined" whenever the javascript is calling the functions in MasterPage.master.vb . The error occurs on code MasterPage.LogOn() , MasterPage.GetClientSession() , and the likes.

Below is my javascript in the MasterPage.master file and the functions LogOn() , GetClientSession() and others are on the MasterPage.master.vb file. This issue only occurs upon the deployment of the system on the test server, and works fine on my local pc.

Anyone who can help please. Thanks so much.

<script type="text/javascript" language="JavaScript">
var SessionTime = 0;
var uname = "";
var status = "";
var clientSession = 0;
var spyOn;
function logon()
{
    MasterPage.LogOn();
    clientSession = MasterPage.GetClientSession().value;
    spyOn = MasterPage.spyOn().value;
    setTimeout("CheckSession()", 60000);
    if (!spyOn)
    {
        var spyWin = open('spy.aspx','UserSecurity','width=250,height=100,left=2000,top=2000,status=0,scrollbar=no,titlebar=no,toolbar=no');
    }
}
function CheckSession()
{
    SessionTime = SessionTime + 1;
    if (SessionTime >= clientSession)
    {
        var uname = document.getElementById("ctl00_hdnUser").value;
        var status = document.getElementById("ctl00_hdnStatus").value;
        var x = MasterPage.SessionEnded(uname, status).value;
        alert(x);
        window.open("Login.aspx","_self");
    }
    setTimeout("CheckSession()", 60000);
}

function RorC() 
{
    var top=self.screenTop; 
    if (top>9000) 
    {
        window.location.href="logout.aspx" ;
    }
} 

function LogMeOut()
{
  window.location.href="logout.aspx" ;
}

function ShowTime() 
{
    var dt = new Date();
    document.getElementById("<%= Textbox1.ClientID %>").value = dt.toLocaleTimeString();

    window.setTimeout("ShowTime()", 1000);
    MasterPage.CheckSession(CheckSession_CallBack);

}  
 window.setTimeout("ShowTime()", 1000);

function CheckSession_CallBack(response)
{
    var ret = response.value;
    if (ret == "")
    {
        isClose = true;
        window.location.href="login.aspx" 
    }
}
</script>

这可以通过添加处理程序是固定的( <httphandlers><system.web>部和<handlers><system.webserver>部分)上web.config支持IIS7和也设置在IIS管理器应用程序池从“集成”改为“经典”。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM