<system.web>
<httpHandlers>
<add verb="*" path="*.aspx"
type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
<add verb="*" path="*.shtml"
type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
<add verb="*" path="*.bobo"
type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
</httpHandlers>
<!-->以下设置数据库缓存依赖方式-->
<caching>
<sqlCacheDependency enabled="true" pollTime="6000">
<databases>
<add name="YD_JWC_JAKE" connectionStringName="cachestr"/>
</databases>
</sqlCacheDependency>
</caching>
<!--
设置 compilation debug="true" 将调试符号插入
已编译的页面中。但由于这会
影响性能,因此只在开发过程中将此值
设置为 true。
-->
<compilation debug="true">
<assemblies>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
</assemblies>
</compilation>
<!--
通过 <authentication> 节可以配置 ASP.NET 使用的
安全身份验证模式,
以标识传入的用户。
-->
<authentication mode="Forms">
<forms loginUrl="login.aspx" name=".AJSUPCXAIUTH"></forms>
</authentication>
<authorization>
<allow users="*"/>
</authorization>
<!--
如果在执行请求的过程中出现未处理的错误,
则通过 <customErrors> 节可以配置相应的处理步骤。具体说来,
开发人员通过该节可以配置
要显示的 html 错误页
以代替错误堆栈跟踪。-->
<customErrors mode="RemoteOnly" defaultRedirect="/ER3.shtml">
<error statusCode="403" redirect="/ER1.shtml" />
<error statusCode="404" redirect="/ER404.shtml" />
</customErrors>
</system.web>
aspnet_regsql -C "data source=127.0.0.1;initial catalog=YD_JWC_JAKE;user id=sa;password=" -ed -et -t "T_NewsClass"
private void getInfoClass( int t)
{
string CacheKey = "cacheclass" + t.ToString();
object objModle = Jake.DataCache.GetCache(CacheKey);//从缓存中获取
DataTable dt=null;
if (objModle == null)//如果缓存中没有则读取数据库
{
Jake.BLL.NewsManage.NewsClass nc = new Jake.BLL.NewsManage.NewsClass();
dt = nc.GetList("").Tables[0];
objModle = dt;
if (objModle != null)
{
System.Web.Caching.SqlCacheDependency dep = new System.Web.Caching.SqlCacheDependency("YD_JWC_JAKE", "T_NewsClass");
Jake.DataCache.SetCache(CacheKey, objModle, dep);
}
}
else
{
dt = (DataTable)objModle; //缓存中有就直接读取缓存,不需要访问数据库
}
DataRow[] drs = dt.Select("","classid");
StringBuilder sb =new StringBuilder();
sb.Append("<ul>");
foreach (DataRow r in drs)
{
string cid=r["ClassId"].ToString();
Security js = new Security();
string decrystr = Jake.Common.ConfigHelper.GetConfigString("DecryStr");//获得加密密钥
cid = js.EncryptQueryString(cid, decrystr);
string cdesc=r["ClassDesc"].ToString();
if (t == 1)
{
sb.Append("<li><a href="/Info" + cid + ".shtml" href="Info" + cid + ".shtml"><span>" + cdesc + "</span></a></li>");
}
else if (t == 2)
{
sb.Append("<li><a href="/File" + cid +".shtml" href="File" + cid +".shtml"><span>" + cdesc + "</span></a></li>");
}
else
sb.Append("<li><a href="/FAQ" + cid + ".shtml" href="FAQ" + cid + ".shtml"><span>" + cdesc + "</span></a></li>");
}
sb.Append("</ul>");
Response.Write(sb);
}
using System;
using System.Collections.Generic;
using System.Web;
using System.Text;
namespace Jake
{
public class DataCache
{
/// <summary>
/// 获取当前应用程序指定CacheKey的Cache值
/// </summary>
/// <param name="CacheKey"></param>
/// <returns></returns>
public static object GetCache(string CacheKey)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
return objCache[CacheKey];
}
/// <summary>
/// 设置当前应用程序指定CacheKey的Cache值
/// </summary>
/// <param name="CacheKey"></param>
/// <param name="objObject"></param>
public static void SetCache(string CacheKey, object objObject)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
objCache.Insert(CacheKey, objObject);
}
/// <summary>
/// 设置已缓存依赖的方式缓存数据
/// </summary>
/// <param name="CacheKey">键值</param>
/// <param name="objObject">缓存对象</param>
/// <param name="dep">缓存依赖项</param>
public static void SetCache(string CacheKey, object objObject, System.Web.Caching.CacheDependency dep)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
objCache.Insert(
CacheKey,
objObject,
dep,
System.Web.Caching.Cache.NoAbsoluteExpiration,//从不过期
System.Web.Caching.Cache.NoSlidingExpiration,//禁用可调过期
System.Web.Caching.CacheItemPriority.Default,
null
);
}
}
}