c# - How to set HTTP cache-control from .net web service? -


itemprop = "text">

after

I inherited a class ( system.Web.Services.WebService with a C # web service ) So a series of webMethods such as:

  [WebMethod, SoapHeader ("title", direction = SoapHeaderDirection.In)] [SoapDocumentMethod ("http://www.myservices.com/Services/ 1.1 #getMediaMetadata ")] Public MediaMetadata getMediaMetadata (String ID) {New MediaService (return). GetMetadata (ID); }  

I am trying to set the cache-control header in response to the HttpResponse.Cache.SetMaxAge Executing the service produces a default header:

  cache-control: private, max-age = 0  

I get the standard Cache SetMaxAge with a hardcoded header:

  HttpContext.Current.Response.AddHeader ("cache-control", "private, max age =" + (int) ttl totalSeconds) ;  

The web server still responds with the default cache-control. I suspect that ASP.NET web services want to adopt the web method after its execution. The suggestion below is not applicable in my situation to use WebMethod's CacheDuration feature.

Any advice?

"text" itemprop = "text">
  [WebMethod (CacheDuration = 60), SoapHeader ("title", direction = SoapHeaderDirection. In]] SoapDocumentMethod ("http://www.myservices.com/Services/1.1####################################) Public MediaMetadata getMediaMetadata (String ID) {New Media Service Return () GetMetadata (ID); }  

This feature should be included in your move.

If you want to use context specifically then

  Context.Response.Cache.SetMaxAge (TimeSpan.FromSeconds (60));  

You will be safe to access references until it is empty. A simple check will solve for you


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -