简体   繁体   English

超时和会话超时问题

[英]timeout and session timeout issue

I have a problem with timeout. 我有超时问题。

firstly the timeout happens every 20 minutes on server even if the time in webconfig is set to 120 mins. 首先,即使webconfig中的时间设置为120分钟,服务器上每20分钟发生一次超时。

second, when the timeout happens it goes to the login page, which is correct but on logging back in it sometimes goes to the default page and sometimes to the page it was previously on. 第二,当超时发生时,它会进入登录页面,这是正确的,但在重新登录时,有时会进入默认页面,有时会进入之前的页面。 I want it to go to the default page everytime. 我希望它每次都进入默认页面。 Like it should remove all the sessions and cookies if thats the problem. 就像它应该删除所有会话和cookie,如果那是问题。

<authentication mode="Forms">
 <forms loginUrl="Login.aspx" defaultUrl="~/Default.aspx" name="GUI"   slidingExpiration="true" timeout="120" path="/">
</forms>
</authentication>
 <authorization>
 <deny users="?"/>
    <allow users="*"/>
 </authorization>

<sessionState mode="InProc" cookieless="false" timeout="120"/>

This is what is there in my webconfig. 这就是我的webconfig中的内容。

This may or may not be related to your specific issue, but in-proc user sessions will not survive application recycles. 这可能与您的具体问题有关,也可能与您没有关系,但是进程内用户会话将无法在应用程序回收中存在。 Check in IIS that your application recycle time is sufficiently high. 在IIS中检查您的应用程序回收时间是否足够高。 Your sessions may indeed last 120 minutes if the application remains active , but once it idles for too long, your app will recycle and your user sessions will become invalidated. 如果应用程序保持活动状态 ,您的会话可能确实持续120分钟,但一旦空闲时间过长,您的应用程序将重新启动,您的用户会话将失效。

My understanding is that with the setup you described ASP.NET doesn't allow unauthenticated web access to your site. 我的理解是,使用您所描述的设置,ASP.NET不允许对您的站点进行未经身份验证的Web访问。 This means that when you go to WebForm1.aspx you get redirected to the login page with this url 这意味着当您转到WebForm1.aspx时,您将被重定向到具有此URL的登录页面

/login.aspx?ReturnUrl=%2fWebForm1.aspx

Then in your login page you might have something like this 然后在您的登录页面中,您可能会有类似这样的内容

    protected void LoginButton_Click(object sender, EventArgs e)
    {

        if (FormsAuthentication.Authenticate(UsernameTextbox.Text, PasswordTextbox.Text))
            FormsAuthentication.RedirectFromLoginPage(UsernameTextbox.Text,false);
        else
           // Let the user know they didn't authenticate

   }

This redirects back to whatever the ReturnUrl specifies. 这会重定向回ReturnUrl指定的任何内容。

Well if you don't want that to happen don't do that. 好吧,如果你不希望这种情况发生,那就不要那样做了。 Do something like this instead. 做这样的事情。

    protected void LoginButton_Click(object sender, EventArgs e)
    {

        if (FormsAuthentication.Authenticate(UsernameTextbox.Text, PasswordTextbox.Text))
            Response.Redirect("default.aspx");
        else
           // Let the user know they didn't authenticate

    }

Check the following things: 检查以下事项:

  • You've definitely got 120 mins in your web.config? 你的web.config中肯定有120分钟?
  • Is this your only web.config? 这是你唯一的web.config吗? If not is it picking these values up from the correct place? 如果不是,它从正确的位置拾取这些值?
  • Use fiddler (or similar) to check your browser is still requesting with a cookie (especially after 20 mins) 使用fiddler(或类似)检查您的浏览器是否仍在请求cookie(特别是在20分钟后)

Hi Take a look at the application pool in iis, check the advanced settings->process model->idle timeout (minutes). 嗨,请查看iis中的应用程序池,检查高级设置 - >进程模型 - >空闲超时(分钟)。 Set this higher than 20 mins. 设置高于20分钟。 Sounds like the worker process is shutting down because its idle. 听起来工作进程因为空闲而关闭。 Often this happens with test systems because they don't get that many hits to stop the idle timeout from kicking in. 这通常发生在测试系统中,因为它们没有得到那么多的命中来阻止空闲超时被踢入。

Cheers Tigger 干杯跳跳虎

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM