locked
why web pages expire when do not active in about 4 minutes RRS feed

  • Question

  • User-475949336 posted

    dear fiend

    The first, thanks the friends in this forum has help me alot of to build the application website ASP.net C#.

    at moment, I finish create  the webapp ( at  you can login with demo/demo), but I'm facing a problem is when i open the web, in about 4 minutes if I don't have any actions on page then click on any  link on  website, it will reditect to login page.

    my web.config:

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <configSections />
      <appSettings />
      
      <system.web>
        <httpRuntime executionTimeout="999999" />
        <compilation debug="true" targetFramework="4.5.2" />
      
        <trust level="Full" />
        <authentication mode="Forms" />
         
    	 <sessionState timeout="60"></sessionState>  
    
      <customErrors mode="Off" defaultRedirect="" />
    
    <machineKey validationKey="308A5193B77D18BB33F286DCC941A54331AE8D000104EAC1DB843D98B1CB457AF9A813B4D5D7D77220987AC8EA478401577194FC20E6CCE8ACEC159C5C59D754" decryptionKey="46C25F7D8BFDE6DAF886AEC2706EFA6A2706C43C752B69C82D5B13A29EA246C1" validation="SHA1" decryption="AES" />
    
      </system.web>
    
      <system.webServer>
        <directoryBrowse enabled="true" />
            <defaultDocument>
                <files>
                    <clear />
                    <add value="default.aspx" />
                    <add value="Default.htm" />
                    <add value="Default.asp" />
                    <add value="index.htm" />
                    <add value="index.html" />
                    <add value="iisstart.htm" />
                </files>
            </defaultDocument>
      </system.webServer>
      
    </configuration>

    In my code I use masterpage (main.master) and session:

    Login.cs

    if user Login susscess:

    HttpContext.Current.Session.Timeout = 60;
    HttpContext.Current.Session["UserName"] = txtUserName.Text;

    In main.master i use:

    <asp:ScriptManager id="toolScriptManageer1" runat="server" EnableHistory="true" EnablePartialRendering="false" EnablePageMethods="true"> </asp:ScriptManager>

    and in Main.master.cs:

     protected void Page_Load(object sender, EventArgs e)
            {
                if (HttpContext.Current.Session["UserName"] == null)
                {
                    Response.Redirect("~/login.aspx");
                    Context.ApplicationInstance.CompleteRequest();
                }
                            
                if (!IsPostBack)
                {               
                      DataTable dt = this.GetData(0);
                      PopulateMenu(dt, 0, null);               
                }
             
                
            }

    Please help me

    Monday, June 8, 2020 2:13 AM

Answers

  • User-475949336 posted

    Hi Friend

    My web hosted in hosting share internet, before in iis_application pool, idle timeout set is 5 minutes, last night I contact admin of hosting for request change idle timeout to 60 minutes, at moment I'm testing is website expire or not.

    this is seting hosting

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 11, 2020 2:20 AM

All replies

  • User753101303 posted

    Hi,

    My first move would be to show HttpContext.Current.Session.SessionID. If the value changed it would confirm you are loosing the session for some reason. If I remember it is written  to the Windows log out of box or at worst you can activate that. Or maybe you are using load balanced servers?

    Edit: for example https://stackoverflow.com/questions/829392/how-to-discover-the-reason-of-asp-net-application-restart  or https://docs.microsoft.com/en-us/previous-versions/iis/6.0-sdk/ms525613(v%3Dvs.90) at the IIS level or https://docs.microsoft.com/en-us/aspnet/web-forms/overview/older-versions-getting-started/deploying-web-site-projects/logging-error-details-with-asp-net-health-monitoring-cs at the ASP.NET level.

    Monday, June 8, 2020 8:00 AM
  • User-475949336 posted
    Hi friend
    I hosting webapp in internet, do not use load balancing.
    Monday, June 8, 2020 8:06 AM
  • User288213138 posted

    Hi test0101,

    when i open the web, in about 4 minutes if I don't have any actions on page then click on any  link on  website, it will reditect to login page.

    Have you restarted your app during this time?

    Best regards,

    Sam

    Tuesday, June 9, 2020 6:43 AM
  • User-821857111 posted

     <authentication mode="Forms" />
         
    	 <sessionState timeout="60"></sessionState> 

    Forms Authentication is not based on session. It is managed via an authentication cookie. It is unlikely that the session is expiring. More likely that the forms authentication ticket is. Try setting a value for the forms auth timeout:

    <authentication mode="Forms">
      <forms loginUrl="~/login.aspx" timeout="60" slidingExpiration="true" />
    </authentication>

    Change login.aspx to the page where the user logs in.

    Tuesday, June 9, 2020 7:07 AM
  • User932909087 posted

    Hi test0101,

    Are you using shared hosting?

    Tuesday, June 9, 2020 7:54 AM
  • User-475949336 posted
    Dear friends
    - yesterday i restarted application pool.
    - i host the web in hosting shared
    Tuesday, June 9, 2020 8:25 AM
  • User-475949336 posted

    Hi

    if I added this to web.config:

    <authentication mode="Forms">

    <forms defaultUrl="~/default.aspx" loginUrl="~/Login.aspx" slidingExpiration="true" timeout="60"></forms>

    </authentication>


    it's apprear error:

    Configuration Error

    Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

    Parser Error Message: The configuration section cannot contain a CDATA or text element.

    Source Error:  An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

    Tuesday, June 9, 2020 9:11 AM
  • User-821857111 posted

    Check that you haven't mistakenly added some other characters to the web.config when you added that section.

    Tuesday, June 9, 2020 11:54 AM
  • User-475949336 posted

    Hi friend

    I edited web.config as below, don't use </forms> tag

     

    <?xml version="1.0"?>
    <configuration>
      <configSections/>
      <appSettings/>
      
      <system.web>
        <httpRuntime maxRequestLength="5182162"  executionTimeout="999999"/>
        <compilation debug="true" targetFramework="4.5.2"/>
    
    <authentication mode="Forms">
    	<forms defaultUrl="~/default.aspx" loginUrl="~/login.aspx" slidingExpiration="true" timeout="60" />
    </authentication>
    
      <sessionState mode="InProc" cookieless="false" timeout="60" > </sessionState>
    
        <trust level="Full"/>
      <customErrors mode="Off" defaultRedirect=""/>
    
    <machineKey validationKey="308A5193B77D18BB33F286DCC941A54331AE8D000104EAC1DB843D98B1CB457AF9A813B4D5D7D77220987AC8EA478401577194FC20E6CCE8ACEC159C5C59D754" decryptionKey="46C25F7D8BFDE6DAF886AEC2706EFA6A2706C43C752B69C82D5B13A29EA246C1" validation="SHA1" decryption="AES" />
    
    
      </system.web>
    
      <system.webServer>
        <directoryBrowse enabled="false"/>
    
    
      </system.webServer>
      
    </configuration>

    But website expired in 5 minutes idle. You can see by login  user/pass: demo/demo  at mysite

     

    Tuesday, June 9, 2020 4:48 PM
  • User288213138 posted

    Hi test0101,

    i host the web in hosting shared

    Can you view the error message in Event Viewer?

    Best regards,

    Sam

    Thursday, June 11, 2020 1:52 AM
  • User-475949336 posted

    Hi Friend

    My web hosted in hosting share internet, before in iis_application pool, idle timeout set is 5 minutes, last night I contact admin of hosting for request change idle timeout to 60 minutes, at moment I'm testing is website expire or not.

    this is seting hosting

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 11, 2020 2:20 AM
  • User-475949336 posted

    Dear friends

    after request hosting administrator change idle timeout in iis_application pool to 60, my web don't expire after 5 minutes.

    Thanks all friends very much!!!

    Thursday, June 11, 2020 3:34 AM