ASP.Net 应用程序超时

发布于 2024-09-01 14:44:23 字数 1635 浏览 2 评论 0原文

我刚刚部署了一个应用程序,出于复杂的原因,该应用程序在第一次需要特定表中的任何数据时(即,当客户第一次请求查看产品时)将数据库中的所有数据存储在模块中,所有产品数据都存储在 ProductManager 类中(其中一个实例存储在 SiteContent 类的共享属性中,使得可以从任何页面轻松访问 ProductManager)

现在忘记您现在可能因为我使用这种方法而对我怒目而视 。 .. 我确信它效率低下,但我现在只学习 .Net 一年左右,所以我仍在学习中,

我注意到的一件事是我可以访问该网站一次,然后 5 分钟后重新访问它。它将再次将所有数据加载到 ProductManager 类中,这似乎是一个 .Net 应用程序超时问题 - 因为会话超时设置为 30 分钟,并且当我登录到管理前端时,它会在之后将我注销。 5 分钟(左右)

有人知道如何改变这个吗?有什么方法可以在代码中更改此设置,而无需联系托管公司?如果代码中没有,是否有任何方法可以在 web.config 中更改此设置?

提前致谢。

此致,

理查德

更多详细信息:

模块(SiteContent)存储每个“Manager”类的实例 - 页面可以调用 Manager.Create、Manager.Update、Manager.Remove 等,并使用 Manager.Items 访问存储在中的项目列表经理(例如 SiteContent.ProductManager.Items 返回数据库中存储的所有产品,而 SiteContent.UserManager.Items 返回数据库中存储的所有用户的列表)。看起来,因为它是一个模块,所以它在用户和页面加载之间共享。

我尝试过返回页面并在 3 - 4 分钟后重新加载它,并且加载正常,但大约 5 分钟后,需要几秒钟才能再次加载页面(不长 - 但我宁愿它不要添加几秒钟每 5 分钟加载一次首页)。

这对我的爸爸(企业老板)来说尤其烦人,当他输入需要超过 5 分钟才能输入的产品,或者输入时,他休息 2 分钟,然后要求他再次登录单击提交,同时丢失所有数据。我没有使用 web.config 身份验证部分中指定的方法进行登录 - 我使用带有登录按钮的表单,单击它会将输入的用户名和密码与每个用户名和密码进行比较用户(通过 SiteContent.UserManager.Items)。

除此之外,我不知道你到底想知道什么......你能详细说明你需要知道的任何细节吗?

在进行一些谷歌搜索时,我发现有一个executionTimeout和一个shutdownTimeout,我将尝试更改它们。

更多细节:

嗯,似乎我刚刚解决了页面加载时间问题。我注意到测试数据库超过13MB实时数据库只有3MB。我对此进行了一些调查。

基本上,错误记录器每次都会记录,如果在目录页面中请求图像,则无法找到图像。测试站点尚未更新图像,因为不需要,因此丢失的图像表已上升到> 。 10MB..必须在测试时禁用图像记录。我删除了该表中的所有内容,现在所有内容都加载得很快。

至于超时的事情,我打算留到以后再做——当我现在有更重要的事情要优先考虑时,我在这上面花了太多时间——这个网站实际上是我在大学的最后一年的项目,我在周五有一个关于它的演示..一定会在这篇文章中添加更多关于我将来如何解决这个问题的细节,所以请时不时地回来看看。.

感谢您花费这么多时间关于这一点..

问候,

理查德

I have an application I have just deployed which, for complicated reasons, stores all the data from the database in a module the first time any data from the specific table is required (i.e. when a customer requests to view a product for the first time, all the product data is stored in the ProductManager class (of which an instance is stored in a shared property of the SiteContent class, making the ProductManager easily accessible from any page).

Now forget that you are probably now glaring at me for using this approach.. I am sure it has its inefficiencies but I have only been studying .Net for a year or so now so I am still learning.

One thing I have noticed is that I can go on the site once, then revisit it 5 minutes later and it will load all the data into the ProductManager class again. It seems this is a .Net application timeout thing - since the session timeout is set to 30 minutes and, when I am logged in on the administration frontend, it logs me out after 5 minutes (ish).

Does anyone have any idea how to change this? Is there any way I can change this in the code without having to contact the hosting company? If not in the code is there any way to change this in the web.config?

Thanks in advance.

Regards,

Richard

More details:

The module (SiteContent) stores an instance of each "Manager" class - pages can call Manager.Create, Manager.Update, Manager.Remove etc etc and use Manager.Items to access a list of items stored in the manager (for example SiteContent.ProductManager.Items returns all the products stored in the database and SiteContent.UserManager.Items returns a list of all users stored in the database). It seems that, because it is a module, it is shared between users and page loads.

I have tried coming back to a page and reloading it after 3 - 4 minutes and it loads fine, but after about 5 minutes it takes a few seconds to load the page again (not long - but I would rather it didnt add a few seconds to the first page load every 5 minutes).

This is particularly annoying for my Dad (the owner of the business) when he is entering products which take more than 5 minutes to enter or which, when entering them, he takes a break for 2 minutes and then it asks him to login again on clicking submit, losing all his data at the same time. I am not using a method specified in the authentication section of the web.config for logging in - I am using a form with a login button, and clicking it compares the entered username and password to that of each user (through SiteContent.UserManager.Items).

Other than this I dont know exactly what you want to know.. can you expand on any specifics you need to know?

On doing some googling I have found out that there is an executionTimeout and a shutdownTimeout which I will have a go at changing..

More details:

hmm seems I just solved the page load time problem.. I noticed that the test database was over 13MB and the live database was only 3MB. I had a little investigate into this.

Basically the error logger will log every time and image cant be found if it is requested in the catalogue page. The test site hasnt been kept up to date with the images, since it doesnt need to be, so the missing image table had gone up to > 10MB.. gonna have to disable image logging on test. I deleted everything from that table and everything loads quickly now.

As for the timeout thing, I am going to leave that till a later date now - I am spending way too much time on this when I have more important things to prioritize at this moment - this website was actually my final year project at uni, and I have a presentation about it on Friday.. will be sure to add more details to this post about how I get on with this problem in the future, so please check back here from time to time..

Thanks for spending so much time on this..

Regards,

Richard

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

沉溺在你眼里的海 2024-09-08 14:44:23

ASP.NET有各种不同的超时,如果您使用FormsAuthentication,那么FormsAuthentication有自己的超时,与Session Timeout不同,您可以检查System.Web的forms身份验证配置部分,您就会知道在哪里增加超时。

另外,您必须编写 IHttpModule,因为在执行身份验证后,您可以通过在 http 模块提供的事件处理程序中初始化适当的会话值来改进您的设计。

ASP.NET have various different timeouts, if you use FormsAuthentication then FormsAuthentication has its own timeout which is different from Session Timeout, you can check System.Web's configuration section of forms authentication, you will know where to increase your timeout.

Plus you will have to write IHttpModule because, after Authentication is performed, you can improve your design by initializing proper session values in the event handlers offered by http modules.

聚集的泪 2024-09-08 14:44:23

您可以混合 2 个超时:

  1. 会话超时 - 服务器从会话映射中清除内存的频率
  2. Auth-cookie 超时 - 客户端浏览器清除 cookie 的频率。

大约 5 分钟的信息存储在客户端的 cookie 中,要更改此时间,请查看 web.config 中的以下行:

    <authentication mode="Forms">
        <forms name=".ASPXFORMAUTH" 
              protection="All" 
              loginUrl="Login.aspx" 
              timeout="20"                 
              defaultUrl="Default.aspx"/>
    </authentication>

You mix 2 timeouts:

  1. Session timeout - how often server cleans memory from session map
  2. Auth-cookie timeout - how often client browser cleans cookies.

Information about 5 mins is stored on client side in cookies, to change this time look at following line in web.config:

    <authentication mode="Forms">
        <forms name=".ASPXFORMAUTH" 
              protection="All" 
              loginUrl="Login.aspx" 
              timeout="20"                 
              defaultUrl="Default.aspx"/>
    </authentication>
执手闯天涯 2024-09-08 14:44:23

我认为这两个超时都不相关。

如果我没看错的话,第一页加载会触发数据加载。该页面获取对数据的引用,将其存储在全局范围内,并从那里使用它。

如果这是正确的,那么听起来 Page 数据将在几分钟后被释放(这是合理的)。由于这释放了对模块的最后一个引用,因此模块被垃圾收集。

您是否尝试过在 Session 对象中存储对数据的引用?这种情况持续的时间要长得多。

听起来你正在尝试进行数据缓存,也许这就是你应该谷歌搜索的内容。

编辑由于您正在做的事情(数据输入)非常简单,因此您的一个基本假设可能是错误的,所以让我们看一下您的一些评论。

  1. 如果您的网络服务器位于某个远程位置,那么您的本地连接速度可能与数据库的读取速度无关,但如果您的意思确实是“几秒钟”,那么这很可能就是页面需要时间加载的原因.

  2. 您想保留多少数据?千字节?兆字节?千兆字节?如果是千字节,您能将其保留在页面上吗?

  3. 在 Application_End() 中放入任何内容都是没有意义的。仅当应用程序本身长时间未使用(例如 20 分钟)以至于 IIS 要求其结束时,才会调用该函数。那么您所做的任何事情都不会产生任何影响。

  4. 管理器不会过期,页面会过期,您可能不应该更改它。

  5. 当您尝试缓存时,是否仍然遇到“数据库数据消失、用户注销、数据输入丢失”的问题?还是只是变得“性能变慢”?

I don't think either of those timeouts is relevant.

If I read you right, the first page load triggers the data load. The page gets a reference to the data, stores it at the global scope, and uses it from there.

If this is correct, it sounds like the Page data is being released after a few minutes (which is reasonable). Since this releases the last reference to the Module, the Module gets garbage-collected.

Have you tried storing a reference to the data in the Session object? That persists a lot longer.

It sounds like you're trying to do data cacheing, maybe that's what you should be googling.

Edit Since what you are doing (data entry) is very straightforward, one of your basic assumptions is probably wrong, so let's look at a couple of your comments.

  1. If your webserver is in some remote location, then your local connection speed is probably irrelevant to how fast the database is read, but if you really mean "a few seconds", that could easily be why the page takes time to load.

  2. How much data are you trying to keep around? Kilobytes? Megabytes? Gigabytes? If it's kilobytes, can you keep it on the page?

  3. Putting anything in Application_End() makes no sense. That only gets called when the application itself has sat unused for so long (say, 20 minutes) that IIS tells it to end. Nothing you do then will make any difference.

  4. The Managers don't expire, the Page expires, and you probably shouldn't change that.

  5. When you tried caching, did you still have the "database data gone, user logged out, data entry lost" problem? Or did it just become "performance slow"?

痕至 2024-09-08 14:44:23

关于您的 5 分钟观察,我发现应用程序池的空闲超时默认为 5 分钟(尽管在 IIS 7.0 中默认值应为 20 分钟)。

查看您的应用程序池的“高级设置”->流程模型->空闲超时(分钟)。您可以通过输入值 0 来完全禁用超时。

Regarding your 5 minute observation, I found that my idle-timeout for the application-pool had defaulted to 5 mins (although the default should be 20 mins in IIS 7.0).

Check out the "Advanced Settings" for your application pool -> Process Model -> Idle-timeout (minutes). You can disable the timeout completely by entering the value 0.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文