2010-03-18 76 views
1

以下面的代码行,将工作罚款AC#asp.net文件:我可以将我的缓存行添加到global.asax吗?

Response.Cache.SetExpires(DateTime.Now.AddSeconds(300)); 
Response.Cache.SetCacheability(HttpCacheability.Public); 

我可以设置这些在Global.asax的一些方式,以便在默认情况下我的整个应用程序将支撑结构300第二次公开缓存?

回答

2

是的,你可以做到这一点,大概就

protected void Application_PreRequestHandlerExecute(HttpApplication sender, EventArgs e) 
{ 
    string sExtentionOfThisFile = System.IO.Path.GetExtension(HttpContext.Current.Request.Path); 

    if (sExtentionOfThisFile.EndsWith("aspx", true, System.Globalization.CultureInfo.InvariantCulture) || 
     sExtentionOfThisFile.EndsWith("ashx", true, System.Globalization.CultureInfo.InvariantCulture) || 
     sExtentionOfThisFile.EndsWith("xml", true, System.Globalization.CultureInfo.InvariantCulture) 
     ) 
    {   
     Response.Cache.SetExpires(DateTime.Now.AddSeconds(300)); 
     Response.Cache.SetCacheability(HttpCacheability.Public);   
    } 
} 

但你不能删除那么容易......如果任何页面需要。

(我已经包含一个页面测试,但只是为了看到它,你可以选择和测试,如果你赢了所有的东西都有这个头。)

相关问题