Asp.net 是否从web.config在WebMethod上设置CacheDuration?
对于ASP.Net web服务,我希望能够在web.config中为所有webmethods或独立webmethods设置CacheDuration,以便在不重新编译解决方案的情况下对其进行调整Asp.net 是否从web.config在WebMethod上设置CacheDuration?,asp.net,web-services,asp.net-4.0,Asp.net,Web Services,Asp.net 4.0,对于ASP.Net web服务,我希望能够在web.config中为所有webmethods或独立webmethods设置CacheDuration,以便在不重新编译解决方案的情况下对其进行调整 [WebMethod(CacheDuration=60)] 能做到吗?怎么做?VB 来源:这似乎是不可能的。在AppSettings中保存值可能吗?问题不是保存值,而是将值应用到webmethod。这显示了如何通过在代码中使用属性值设置缓存持续时间,正如我在问题中所做的那样。我想从web.config
[WebMethod(CacheDuration=60)]
能做到吗?怎么做?VB
来源:这似乎是不可能的。在AppSettings中保存值可能吗?问题不是保存值,而是将值应用到webmethod。这显示了如何通过在代码中使用属性值设置缓存持续时间,正如我在问题中所做的那样。我想从web.config执行此操作
Public Class Service1
Inherits System.Web.Services.WebService
<System.Web.Services.WebMethod(CacheDuration:=60)> _
Public Function ConvertTemperature(ByVal dFahrenheit As Double) _
As Double
ConvertTemperature = ((dFahrenheit - 32) * 5) / 9
End Function
End Class
public class Service1 : System.Web.Services.WebService
{
[System.Web.Services.WebMethod(CacheDuration=60)]
public double ConvertTemperature(double dFahrenheit)
{
return ((dFahrenheit - 32) * 5) / 9;
}
}