Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I had a problem with session operation, In my web application ,I write a session timeout in web.config but the problem is ,the application is time out(in 20 mins) while running the application(while doing the process..) . I guess the problem is the session is not refreshing ..

My session code is below..

C#
<sessionState mode="InProc" cookieless="false" timeout="20"/>


So plz suggest a good solution for me..it will helpful to me.

and also I use a javascript ,here is the code...

XML
<script language="javascript" type="text/javascript">

    var sessionTimeout = "<%= Session.Timeout %>";
//    debugger;
    //To redirect to the welcome page
    setTimeout('RedirectToWelcomePage()', parseInt(sessionTimeout) * 60 * 1000);
    //Session timeout
    function RedirectToWelcomePage() {

        var url = window.location.toString();
        var loginPage = "/ContentPages/Common/Home.aspx";
        var urlparts = url.split('/');
        var loginUrl = urlparts[0] + "//" + urlparts[2] + "/" + urlparts[3] + loginPage;
        //alert("Your session has timed-out, please re-login.");
        //window.location = loginUrl;
        if (url.match("Login.aspx") == null) {
            alert("Your session has timed-out, please re-login.");
            window.location = loginUrl;
        }


    }

</script>
Posted
Updated 25-Oct-12 1:37am
v3
Comments
Sushil Mate 25-Oct-12 3:06am    
you write session timeout 20 mins & it will be for 20 mins. what exactly problem you are facing with session?
aravindnass 25-Oct-12 4:16am    
sir..the problem I am facing is ...while doing the application the session time is out..( I want (normally when session is out ,this is no action takes in a particular interval)but while I doing some working (abt 20 mins) .it will show the message session time out..

and use a javascript..here the code..

<script language="javascript" type="text/javascript">

var sessionTimeout = "<%= Session.Timeout %>";
// debugger;
//To redirect to the welcome page
setTimeout('RedirectToWelcomePage()', parseInt(sessionTimeout) * 60 * 1000);
//Session timeout
function RedirectToWelcomePage() {

var url = window.location.toString();
var loginPage = "/ContentPages/Common/Home.aspx";
var urlparts = url.split('/');
var loginUrl = urlparts[0] + "//" + urlparts[2] + "/" + urlparts[3] + loginPage;
//alert("Your session has timed-out, please re-login.");
//window.location = loginUrl;
if (url.match("Login.aspx") == null) {
alert("Your session has timed-out, please re-login.");
window.location = loginUrl;
}


}

</script>
[no name] 25-Oct-12 3:26am    
What kind of error you're getting..?
aravindnass 25-Oct-12 4:16am    
sir..the problem I am facing is ...while doing the application the session time is out..( I want (normally when session is out ,this is no action takes in a particular interval)but while I doing some working (abt 20 mins) .it will show the message session time out..

and use the javascript ...here the code...

<script language="javascript" type="text/javascript">

var sessionTimeout = "<%= Session.Timeout %>";
// debugger;
//To redirect to the welcome page
setTimeout('RedirectToWelcomePage()', parseInt(sessionTimeout) * 60 * 1000);
//Session timeout
function RedirectToWelcomePage() {

var url = window.location.toString();
var loginPage = "/ContentPages/Common/Home.aspx";
var urlparts = url.split('/');
var loginUrl = urlparts[0] + "//" + urlparts[2] + "/" + urlparts[3] + loginPage;
//alert("Your session has timed-out, please re-login.");
//window.location = loginUrl;
if (url.match("Login.aspx") == null) {
alert("Your session has timed-out, please re-login.");
window.location = loginUrl;
}


}

</script>

1 solution

You can use a timer to force the page redirect to login page after 20 minutes.
ASP.NET
<body>
    <form id="form1" runat="server">
    <asp:scriptmanager id="ScriptManager1" runat="server" xmlns:asp="#unknown">
    </asp:scriptmanager>
    <asp:timer id="Timer1" runat="server" interval="1200000" ontick="Timer1_Tick" xmlns:asp="#unknown">
    </asp:timer>
    </form>
</body>

Code behind:
C#
public partial class WebForm1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
            
    }

    protected void Timer1_Tick(object sender, EventArgs e)
    {
        Response.Redirect("~/ContentPages/Common/Home.aspx", true);
    }
}
 
Share this answer
 
Comments
aravindnass 26-Oct-12 1:27am    
hai..adriancs , thank you for you solution ,but if I use these I want to use in every pages..Can you tell me how to write these in web.config ,if that I don't want use these in every page ...its very helpfull....
adriancs 26-Oct-12 1:40am    
Put the code in master page.

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