This documentation is archived and is not being maintained.
HttpCachePolicy.SetMaxAge Method
.NET Framework 1.1
Sets the Cache-Control: max-age HTTP header based on the specified time span.
[Visual Basic] Public Sub SetMaxAge( _ ByVal delta As TimeSpan _ ) [C#] public void SetMaxAge( TimeSpan delta ); [C++] public: void SetMaxAge( TimeSpan delta ); [JScript] public function SetMaxAge( delta : TimeSpan );
Parameters
- delta
- The time span used to set the Cache- Control: max-age header.
Exceptions
| Exception Type | Condition |
|---|---|
| ArgumentOutOfRangeException | delta is less than 0 or greater than one year. |
Remarks
Max-age is the maximum absolute time a document is allowed to exist before being considered stale.
SetMaxAge does not use sliding expiration and will fail if the expiration date violates the principle of restrictiveness.
Example
The following example sets the Cache-Control: max-age header to 0 hours, 30 minutes, and 0 seconds.
[Visual Basic] Dim ts As New TimeSpan(0,30,0) Response.Cache.SetMaxAge(ts) [C#] TimeSpan ts = new TimeSpan(0,30,0); Response.Cache.SetMaxAge(ts); [C++] TimeSpan ts = TimeSpan(0,30,0); Response->Cache->SetMaxAge(ts); [JScript] var ts : TimeSpan = new TimeSpan(0,30,0) Response.Cache.SetMaxAge(ts)
Requirements
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
See Also
HttpCachePolicy Class | HttpCachePolicy Members | System.Web Namespace
Show: