Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 :

C#
protected void PreRender(object sender, EventArgs e)
    {


XML
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
XML
<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
Posted
Comments
Richard C Bishop 24-Oct-13 18:29pm    
I believe the "~/" reference only works on the server side in Visual Studio solutions. That may be part of the problem. It signifies a path that originates in the root.
sumanth n 24-Oct-13 18:48pm    
Thanks for replying richcb. My actual issue is '/Project1/Files/' this particular path is coming into my path as default i think becoz of this particular path it is showing an error can u please say why this is particular path is visible . once check this
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

u can find in my script im declaring my href as'~/Folder/LogOut.aspx' thats but when we see in the error it is showing /Project/Files/~/Folder/LogOut.aspx
idenizeni 24-Oct-13 20:23pm    
When you set the path as '~/Folder/LogOut.aspx' it's not seen as an absolute path on the client and so it prefixes the relative path the browser is currently at. I'm guessing you are at some url like 'http://siteroot.com/Project1/Files/'. If this is the case then check my posted solution below.

1 solution

Try changing this bit of code...
C#
window.location.assign('~/Folder/LogOut.aspx');

... to be this...
C#
window.location.assign(" + ResolveUrl("~/") + "'/Folder/LogOut.aspx');

Try replacing your PreRender routine with this code...
C#
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);
        }
 
Share this answer
 
v3
Comments
sumanth n 25-Oct-13 3:50am    
Sure Ill check it out Thanks for sharing your valuable information Thank You
sumanth n 25-Oct-13 9:05am    
when i placed the line of code as u mentioned then im getting an error saying to "newline in constant" can u please help out with this error

sumanth n 25-Oct-13 9:43am    
not working idenizeni
idenizeni 25-Oct-13 13:13pm    
I've updated my answer, sorry for the bad code. I've tested the updated code on my system and it works.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900