locked
Session Time Out Error RRS feed

  • Question

  • User1109811461 posted

    hi all expertise

    i wan to implement session time out, means that if the user don't do anything at the system after a few minute, the system will produce a

    pop up message. i already try to implement this code but  got  error message please see my errror message below:

    i also don't know this code below is correct or not as what i want please give me a suggestion all expertise here, i'm new in programmingEmbarassed

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: BC30203: Identifier expected.

    Source Error:

    Line 5:  
    Line 6:    <script language="javascript" type="text/javascript">
    Line 7: var sessionTimeoutWarning = "<%= System.Configuration.ConfigurationSettings.AppSettings["SessionWarning"].ToString()%>"; 
    Line 8: var sessionTimeout = "<%= Session.Timeout %>"; Line 9: var timeOnPageLoad = new Date();

    My Code:

    <script language="javascript" type="text/javascript">
            var sessionTimeoutWarning = "<%= System.Configuration.ConfigurationSettings.AppSettings["SessionWarning"].ToString()%>";
            var sessionTimeout = "<%= Session.Timeout %>";
            var timeOnPageLoad = new Date();
     
            //For warning
            setTimeout('SessionWarning()', parseInt(sessionTimeoutWarning) * 60 * 1000);
            //To redirect to the welcome page
            setTimeout('RedirectToWelcomePage()',parseInt(sessionTimeout) * 60 * 1000);

            //Session Warning
            function SessionWarning()
            {
                //minutes left for expiry
                var minutesForExpiry =  (parseInt(sessionTimeout) - parseInt(sessionTimeoutWarning));
                var message = "Your session will expire in another " + minutesForExpiry + " mins! Please Save the data before the session expires";
                alert(message);
                var currentTime = new Date();
                
                //time for expiry
                var timeForExpiry = timeOnPageLoad.setMinutes(timeOnPageLoad.getMinutes()
                    + parseInt(sessionTimeout));

                //Current time is greater than the expiry time
                if(Date.parse(currentTime) > timeForExpiry)
                {
                    alert("Session expired. You will be redirected to welcome page");
                    window.location = "MainPage.aspx";
                }
            }

            //Session timeout
            function RedirectToWelcomePage()
            {
                alert("Session expired. You will be redirected to welcome page");
                window.location = "MainPage.aspx";
            }
      </script>   

    i just copy this code from this web site

    http://www.codeproject.com/Articles/227382/Alert-Session-Time-out-in-ASP-Net

    Saturday, December 29, 2012 6:56 PM

Answers

  • User-1354034460 posted

    Hai

    Check your webconfig and  your code from vijay_myl ways

     

    <configuration>

          <appSettings>

                <add key="var1"value="SomeValue"/>

          </appSettings>

          <connectionStrings>

    <add name="MyConnString"connectionString="Data   Source=(local);Initial Catalog=Northwind;Integrated Security=True;"/>

          </connectionStrings>

    ...

    <configuration>

     

    To read these entries using javascript, use the below:

        <script type="text/javascript">

        function ReadConfigSettings()

        {

      var conn='<%=ConfigurationManager.ConnectionStrings["MyConnString"].ConnectionString %>'

            alert(conn);

            var v1 = '<%=ConfigurationManager.AppSettings["var1"].ToString() %>'

            alert(v1);

        }

        </script>

     

     To read these entries using JavaScript , use the below:

        

    and look this 

    http://forums.asp.net/t/1795429.aspx/1

    http://forums.asp.net/t/1552985.aspx/1

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, December 30, 2012 3:39 AM

All replies

  • User-663458986 posted

    Seems to be wrong string assignment. try this

    var sessionTimeoutWarning = '<%= System.Configuration.ConfigurationSettings.AppSettings["SessionWarning"].ToString()%>';
    use single quotes ( ' ) not ( " )
    Saturday, December 29, 2012 11:43 PM
  • User3866881 posted

    var sessionTimeoutWarning = "<%= System.Configuration.ConfigurationSettings.AppSettings["SessionWarning"].ToString()%>";

    Hi,

    In fact I think you can just use single quote sample,sample like this:

    var sessionTimeoutWarning = '<%= System.Configuration.ConfigurationSettings.AppSettings["SessionWarning"]%>';
    Sunday, December 30, 2012 12:27 AM
  • User1109811461 posted

    hi expertise i still got same error, what next need to do...?

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: BC30203: Identifier expected.

    Source Error:

    Line 5:     
    Line 6:     <script language="javascript" type="text/javascript">
    Line 7: var sessionTimeoutWarning = '<%= System.Configuration.ConfigurationSettings.AppSettings["SessionWarning"].ToString()%>'; 
    Line 8: var sessionTimeout = "<%= Session.Timeout %>"; Line 9: var timeOnPageLoad = new Date();

    Sunday, December 30, 2012 1:06 AM
  • User-1354034460 posted

    try this 

    var sessionTimeoutWarning="<%: System.Configuration.ConfigurationSettings.AppSettings["SessionWarning"].ToString()%>"; 
    Sunday, December 30, 2012 2:10 AM
  • User-663458986 posted

    i think something is wrong with the "value" of your "key" in AppSettings.

    could you paste the value here?

    Sunday, December 30, 2012 2:15 AM
  • User1109811461 posted

     hi furry

     which value did you talking about...please guide i'm new in programmingCool

    Sunday, December 30, 2012 2:45 AM
  • User-663458986 posted

    the value in your appsettings for "SessionWarning"

    Sunday, December 30, 2012 2:51 AM
  • User1109811461 posted

    hi furry

    i did not set anything on thatCool because on the web site does not told me to do that thing..please guide me

    hi dotnetramesh you give me a broken link,,, please check it

    Sunday, December 30, 2012 3:11 AM
  • User-663458986 posted

    in your provided link, it says 

    "sessionTimeoutWarning: is a predefined value in the application configuration. Say 18 minutes."


    which means you need to add a Setting key in your Web.Config file.

    <appSettings>
        <add key ="SessionWarning" value ="1"/>
      </appSettings> 

    if you already have AppSettings in your config file, than only add 

    <add key ="SessionWarning" value ="1"/>



    Sunday, December 30, 2012 3:20 AM
  • User1109811461 posted

    still got error message furry

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: BC30203: Identifier expected.

    Source Error:

    Line 5:     
    Line 6:     <script language="javascript" type="text/javascript">
    Line 7: var sessionTimeoutWarning = '<%= System.Configuration.ConfigurationSettings.AppSettings["SessionWarning"].ToString()%>'; 
    Line 8: var sessionTimeout = "<%= Session.Timeout %>"; Line 9: var timeOnPageLoad = new Date();
    Sunday, December 30, 2012 3:29 AM
  • User-1354034460 posted

    Hai

    Check your webconfig and  your code from vijay_myl ways

     

    <configuration>

          <appSettings>

                <add key="var1"value="SomeValue"/>

          </appSettings>

          <connectionStrings>

    <add name="MyConnString"connectionString="Data   Source=(local);Initial Catalog=Northwind;Integrated Security=True;"/>

          </connectionStrings>

    ...

    <configuration>

     

    To read these entries using javascript, use the below:

        <script type="text/javascript">

        function ReadConfigSettings()

        {

      var conn='<%=ConfigurationManager.ConnectionStrings["MyConnString"].ConnectionString %>'

            alert(conn);

            var v1 = '<%=ConfigurationManager.AppSettings["var1"].ToString() %>'

            alert(v1);

        }

        </script>

     

     To read these entries using JavaScript , use the below:

        

    and look this 

    http://forums.asp.net/t/1795429.aspx/1

    http://forums.asp.net/t/1552985.aspx/1

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, December 30, 2012 3:39 AM