IIS自动关闭我的应用程序? [英] IIS turned off my application automatically?

查看:321
本文介绍了IIS自动关闭我的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只注意到IIS关闭了我的ASP.NET Web应用程序后会自动将其闲置20分钟。该网站托管在Godaddy.com。

I just noticed that IIS turned off my ASP.NET web application automatically after it idled 20 minutes. The website is hosted on Godaddy.com.

下面是一个记录的的Application_Start和Application_End方法全局类。我上传的图片,我看到的结果。

Below is the Global class which logs the Application_Start and Application_End methods. And the image I uploaded is the result that I saw.

这在2013年5月24日6点42分四十零秒最后一个电话我在6点22分01秒后没有关闭。 (20分钟,华...)后的一天,我做了另外一个电话在2013年5月25日3时05分27秒,该网站被唤醒。

It turned off at 2013-05-24 06:42:40 after the last call I did at 06:22:01. (20 minutes, hua...) After one day, I did another call at 2013-05-25 03:05:27, the website was awaken.

奇怪? 我不希望我的网站上睡觉。有(技巧),反正以保持清醒所有的时间?

谢谢,万里

public class Global : HttpApplication
{
    private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

    protected void Application_AuthenticateRequest(object sender, EventArgs e)
    {
        log.Debug("Application_AuthenticateRequest -> " + base.Context.Request.Url);
    }

    protected void Application_End(object sender, EventArgs e)
    {
        log.Info("Application_End");
    }

    protected void Application_Start(object sender, EventArgs e)
    {
        log.Info("Application_Start");
    }
}

推荐答案

在IIS / asp.net是关闭应用程序,如果你没有一段时间的任何要求,以节省资源。

The IIS/asp.net is turn off the application if you do not have any request for some time to save resource.

现在这个通常在服务器端处理,如果你想避免它,但在你的情况下,你不能用IIS安装干扰,使一招是创建一个计时器,每10分钟左右,一个页面的读取。

Now this usually handle on server side if you wish to avoid it, but in your case you can't interfere with the IIS setup, so one trick is to create a timer that reads every 10 minutes or so one page.

您启动应用程序启动时,不要忘记停止它,当应用程序熄灭。

You start it when application starts, and do not forget to stop it when application is go off.

// use this timer (no other)
using System.Timers;

// declare it somewhere static
private static Timer oTimer = null;

protected void Application_Start(object sender, EventArgs e)
{
    log.Info("Application_Start");

    // start it when application start (only one time)
    if (oTimer == null)
    {
        oTimer = new Timer();

        oTimer.Interval = 14 * 60 * 1000; // 14 minutes
        oTimer.Elapsed += new ElapsedEventHandler(MyThreadFun);
        oTimer.Start();
    }   
}

protected void Application_End(object sender, EventArgs e)
{
    log.Info("Application_End");

    // stop it when application go off
    if (oTimer != null)
    {
        oTimer.Stop();

        oTimer.Dispose();
        oTimer = null;
    }   
}


private static void MyThreadFun(object sender, ElapsedEventArgs e)
{
    // just read one page
    using (System.Net.WebClient client = new System.Net.WebClient())
    {
        client.DownloadData(new Uri("http://www.yoururl.com/default.aspx"));
    }
}

一个说明,除非你需要因为你创建一个线程多生活永远不要使用这一招。通常谷歌读取网页,并保持温暖,自动关闭通常,如果你有一个非常新的网站,谷歌和其他搜索引擎没有启动索引,或者当你有一个只有两个页面,永远不会改变。

One note, do not use this trick unless you needed because you create one more thread living for ever. Usually google reads the web pages and keep it "warm", the auto turn off usually occurs if you have a very new site that google and other search engines did not start to index, or if you have one two page only that never change.

所以我不推荐这样做 - 而且不差地关闭网站并节省资源,您的网站是从任何被遗忘的记忆开放清楚,重新开始...

So I do not recomended to do it - and is not bad to close your site and save resource, and your site is clear from any forgotten open memory and start fresh...

保持你的ASP.Net网站温暖和快速24/7 结果
应用程序初始化模块IIS 7.5 结果
<一href=\"http://weblogs.asp.net/scottgu/archive/2009/09/15/auto-start-asp-net-applications-vs-2010-and-net-4-0-series.aspx\"相对=nofollow>自动启动ASP.NET应用程序(VS 2010和.NET 4.0系列)

这篇关于IIS自动关闭我的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆