0

What is HTTP headers in asp.net. How do they work? I want to use them to cache in output cache for varybyheader.

2
  • If you don't know what HTTP Headers are for, why do you want to use them for output caching? Perhaps understanding this will help us answer your question =) Commented Jan 7, 2011 at 8:51
  • 1
    hanselman.com/blog/… Commented Jan 7, 2011 at 8:52

3 Answers 3

4

Each piece of data is transmitted over the internet via a protocol called HTTP - you can't do anything about this as its the way the internet has been designed.

Each piece of this data is seperated up into chunks - each of which needs a header to provide an explanation to its contents, this is a HTTP Header.

Using these headers you can request the browser to perform certain actions on your behalf (it is under no obligation to follow) such as:

  • Redirect to another page
  • Request the browser to cache

I believe the second is the one you require.

ASP.NET is wonderful however - you don't need to fiddle about with HTTP Headers. The framework will do that for you.

Sign up to request clarification or add additional context in comments.

1 Comment

Really nice answer to an evasive question !
1

Output caching in asp.net can be done by means of declarative syntax meaning in the markup page you can declare them alone with page directives .Syntax given below.

<%@ OutputCache Duration="#ofseconds" Location="Any | Client | Downstream | Server | None | ServerAndClient " Shared="True | False" VaryByControl="controlname" VaryByCustom="browser | customstring" VaryByHeader="headers" VaryByParam="parametername" VaryByContentEncoding="encodings" CacheProfile="cache profile name | ''" NoStore="true | false" SqlDependency="database/table name pair | CommandNotification" ProviderName="Provider Name"
%>

Suppose if you want to cache the page based on the language you can use the HTTP headers called "Accept Language". So if it will cache page content for languages specific like French,Chinese,Japanese.

<%@ OutputCache Duration="10800" VaryByParam="State;City" VaryByHeader="Accept-Language" %>

Like this you can cache the page based on HTTP headers .

Accept Content-Types that are acceptable Accept: text/plain Accept-Charset Character sets that are acceptable Accept-Charset: utf-8 Accept-Encoding Acceptable encodings Accept-Encoding: Accept-Language Acceptable languages for response Accept-Language: en-US

Links referred: http://msdn.microsoft.com/en-us/library/ms972362.aspx http://msdn.microsoft.com/en-us/library/hdxfb6cy.aspx http://en.wikipedia.org/wiki/List_of_HTTP_header_fields

Comments

0

There is a good article that might help you with this: link. To quote: "HTTP Headers are used to provide the web server with information to assist with handling the request"

Hope it helps.

1 Comment

... and the browser. You have both Request and Response http headers :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.