As demonstrated in Sections 4.6 and 4.7, it is possible to be very explicit about how
pages can be output cached.The last technique for controlling how pages can be cached
involves varying by HTTP headers presented by the client browser:
<%@OutputCache Duration="60" VaryByParam="none"
VaryByHeader="Accept-Language" %>
[content]
or
<script runat="server">
' Note, this only works for pages and not user controls
Sub Page_Load(object As Sender, e As EventArgs)
Response.Cache.SetExpires(DateTime.Now.AddSeconds(100))
Response.Cache.SetCacheability(HttpCacheability.Public)
Response.Cache.SetValidUntilExpires(true)
Response.Cache.VaryByHeaders("Accept-Language") = true;
End Sub
</script>
[content]
Comments
All browsers send over headers that provide information about the browser, or other relevant
information pertinent to the request. As discussed in Section 4.7, browsers provide
a user/agent header that allows ASP.NET to generate different content based on the
browser type. In addition to the user/agent header, several other headers are sent over
that you can vary by.The most common is the
Accept-Language header.
The Accept-Language header provides information about the language the client
prefers. For example, for United States English, the value is EN-US, whereas a request
from the United Kingdom might be EN-EN, France is FR-FR, and Japan is JP-JP.
When the output cache is varied by the Accept-Language header, different localized
versions of the page can be stored and served from the cache-assuming you've written
the code to do so.
No comments:
Post a Comment