java脚本中的重定向错误 [英] Redirection error in java script

查看:73
本文介绍了java脚本中的重定向错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我刚刚有一个javascript,它有助于在一段会话时间之后重定向到某个页面

i只有一段代码:



 受保护  void  PreRender ( object  sender,EventArgs e)
{





< pre lang =xml> int int_MilliSecondsTimeOut =(this.Session.Timeout * 60000);

string str_Script = @

< script type =' text / javascript' >

intervalset = window.setInterval('Redirect()' ,+ int_MilliSecondsTimeOut.ToString()+ @);

函数Redirect()

{

window.location.assign('〜 /Folder/LogOut.aspx');
// window.location.href ='';

}

< / script > ;

ClientScript.RegisterClientScriptBlock(this.GetType(),Redirect,str_Script);



}



i在我的有效部分使用此方法,如:



this.PreRenderComplete + = new EventHandler(PreRender);



并在我的网络配置文件中添加以下代码行

 <   system.web  >  

< sessionState mode = InProc < span class =code-attribute> timeout = 1 / >
< / system.web >





此后我只显示我的项目登录页面,并在进入主页后1分钟后进入确切的值时间需要重定向到logout.aspx页面,但我得到一个错误说





---------- -------------------------------------------------- --------------------



无法找到资源。

描述:HTTP 404.您要查找的资源(或其中一个依赖项)可能已被删除,名称已更改或暂时不可用。请查看以下网址,确保拼写正确。



请求的URL:/Project1/Files/~/Folder/LogOut.aspx



我不是能够理解为什么我将我的路径作为'/ Project1 / Files /'作为默认值而不在我的Href路径中添加它可以任何人帮助我为什么得到它以及如何解决它

解决方案

尝试更改这段代码...

  window.location.assign(' 〜/ Folder / LogOut.aspx');  



......就是这样......

  window.location.assign(  + ResolveUrl(〜/  )+ '  / Folder / LogOut.aspx' );  



尝试使用此代码替换PreRender例程...

 受保护  void  PreRender( object  sender,EventArgs e)
{
int int_MilliSecondsTimeOut =( this .Session。超时* 60000 );

string str_Script = @ < script type ='text / javascript'>
intervalset = window.setInterval('Redirect()',
+ int_MilliSecondsTimeOut.ToString()+ @ );
函数Redirect()
{
window.location.assign('
+ ResolveUrl ( 〜/)+ @ Folder / LogOut.aspx');
}
< / script>
;

ClientScript.RegisterClientScriptBlock( this .GetType(), 重定向,str_Script);
}


Hi
I just had a javascript where it helps to redirect to some page after some set of session time
i just had of a code :

protected void PreRender(object sender, EventArgs e)
    {



int int_MilliSecondsTimeOut = (this.Session.Timeout * 60000);

                string str_Script = @"

   <script type='text/javascript'>

    intervalset = window.setInterval('Redirect()'," + int_MilliSecondsTimeOut.ToString() + @");

    function Redirect()

    {

window.location.assign('~/Folder/LogOut.aspx');
     //  window.location.href='';

    }

</script>";

                ClientScript.RegisterClientScriptBlock(this.GetType(), "Redirect", str_Script);


}

i used this method in my valid part like :

this.PreRenderComplete += new EventHandler(PreRender);

and add these line of code in my web config file

<system.web>
   
    <sessionState mode="InProc" timeout="1"/>
  </system.web>



after this i just run my project login page displayed and i ogged in with the exact values after getting into the home page after 1 minute of time it need to redirect to logout.aspx page but im getting an error saying


--------------------------------------------------------------------------------

The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Project1/Files/~/Folder/LogOut.aspx

I am not able to understand why i am get my path as '/Project1/Files/' as default without adding it in my Href path can any one help out why iam getting it and how to resolve it

解决方案

Try changing this bit of code...

window.location.assign('~/Folder/LogOut.aspx');


... to be this...

window.location.assign(" + ResolveUrl("~/") + "'/Folder/LogOut.aspx');


Try replacing your PreRender routine with this code...

protected void PreRender(object sender, EventArgs e)
        {
            int int_MilliSecondsTimeOut = (this.Session.Timeout * 60000);            

            string str_Script = @"<script type='text/javascript'>    
            intervalset = window.setInterval('Redirect()'," + int_MilliSecondsTimeOut.ToString() + @");
            function Redirect()
            {
                window.location.assign('" + ResolveUrl("~/") + @"Folder/LogOut.aspx');
            } 
        </script>";

            ClientScript.RegisterClientScriptBlock(this.GetType(), "Redirect", str_Script);
        }


这篇关于java脚本中的重定向错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆