在Web Service中的ASP.net中进行缓存 [英] Caching in ASP.net in Web Service

查看:70
本文介绍了在Web Service中的ASP.net中进行缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个webService.
因为我正在使用缓存.

我编写了以下代码以将数据表存储在缓存中.

I m having a webService.
In that I m using Caching.

I have wrote following code to store datatable in cache.

using System.Web.Caching;

Cache.Insert("dt", dt, null, DateTime.Now.AddHours(1), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Default, null);



它给我这样的错误,例如非静态字段需要对象引用.

我该如何消除此错误



It give me error like "An object Reference is required for non static field.

How can i remove this error

推荐答案

您似乎正在Page 类(公开了Cache 属性)之外使用它.如果您有权访问HttpContext,则可以通过HtpContext.Current.Cache进行访问.仍然值得尝试.
You seem to be using it outside the Page class (which exposes a Cache property). If you have access to HttpContext, then you can get it through HtpContext.Current.Cache. Worth trying out anyway.


这篇关于在Web Service中的ASP.net中进行缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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