feanz
9/18/2013 - 2:45 PM

Expire Header WCF Service

Expire Header WCF Service

public static class Extensions
{
  public static string ToExpireString(this DateTime dateTime)
  {
    return dateTime.ToString("ddd, dd MMM yyy HH:mm:ss 'GMT'");
  }
}


public static class Expires
{
  public static void Set(int seconds)
  {
    var response = WebOperationContext.Current.OutGoingResponse;
    if(response != null)
    {
      var expires = DateTime.UtcNow.AddSeconds(seconds).ToEpireString();
      response.Headers.Add(HttpReponseHeader.Expires, expires);
    }
  }
}