troubleshooting Question

IIS 7.5/ASP.NET/VB: Cache Control and Vary Headers

Avatar of hankknight
hankknightFlag for Canada asked on
ASP.NETVisual Basic.NETMicrosoft IIS Web Server
3 Comments1 Solution1516 ViewsLast Modified:
I use Visual Basic / ASP.NET on IIS 7.5.  Want the "Cache-Control" header to be sent with a value of "Public" and I do NOT want the "Vary" header to be sent.  The following code sets the "Cache-Control" header to "public" with a lowercase "p" instead of an uppercase "P" and it does NOT remove the "Vary" header.

How can I customize the value of the "Cache-Control" header and remove the "Vary" header?
Imports System.Web
Imports System.IO
Namespace org.HeaderHack
	Public Class CustomHeaderModule
		Implements IHttpModule
		Public Sub Dispose() Implements IHttpModule.Dispose
		End Sub
		Public Sub Init(context As HttpApplication) Implements IHttpModule.Init
			AddHandler context.PreSendRequestHeaders, AddressOf OnPreSendRequestHeaders
			AddHandler context.PreRequestHandlerExecute, New EventHandler(AddressOf OnPreRequestHandlerExecute)
		End Sub
		Private Sub OnPreSendRequestHeaders(sender As Object, e As EventArgs)
			HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public)
			HttpContext.Current.Response.Headers.Remove("Vary")

		End Sub
		Public Sub OnPreRequestHandlerExecute(source As [Object], e As EventArgs)
			Dim url As [String] = HttpContext.Current.Request.FilePath.ToString()
			Dim ext As [String] = Path.GetExtension(url)
		End Sub
	End Class
End Namespace

Open in new window

ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros