We had a requirement to modify Vary Response Header to 'User-Agent' for mobile site SEO for google. Have you faced a situation that your changed Vary header is not getting reflected on the Response Headers on ASP.NET webpage?
We tried to modify the header from Page_Load event of a webpage. but when page is loaded, my HttpWatch/Fiddler is not showing Vary header as 'User-Agent', it is still showing 'Accept-Encoding' instead. Checkout my code:
This issue is already addressed by an official patch to IIS. We can download the HotFix from Microsoft - http://support.microsoft.com/kb/2877816
After installing this HotFix, this issue is resolved!!
We can now play with Vary header along with Dynamic Content Compression module!!
We tried to modify the header from Page_Load event of a webpage. but when page is loaded, my HttpWatch/Fiddler is not showing Vary header as 'User-Agent', it is still showing 'Accept-Encoding' instead. Checkout my code:
using System; using System.Collections.Generic; using System.Web; using System.Web.UI; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Response.Write("Hello"); // Modify Vary Response Header Response.AppendHeader("Vary", "User-Agent"); } }Above code failed so we also tried to append these headers at Page_LoadComplete and context_EndRequest event(last event in page life cycle) assuming that the headers were tampered in between (Between Page_Load and context_EndRequest). See below snap, showing our code not working, means showing Vary as 'Accept-Encoding' instead of 'User-Agent'. So, something strange was happening here.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBoVjFF38bo5zK6Y3Km1iprbq2Xhwqi1NMbetG6FCS8uJa9kQCTHU1R1Az0TKq50NiPU32MYJt6FFH62oRTs0_sameoBVCYrM83V2_hu4IAM2T7b1D0nxFF4126rNLH6jWxLVhXQ2vSLo/s1600/vary-header-not-working.png)
How we found the cause and the solution
One thing was sure that the headers are overwritten from IIS level, because our modified headers set in context_EndRequest event(last event in page life cycle) were also getting overwritten. After spending few hours, I came to know that dynamic compression module from IIS overwrites the Vary header to 'Accept-Encoding'. Disabling this module solved our problem. Such a nasty bug it is!!This issue is already addressed by an official patch to IIS. We can download the HotFix from Microsoft - http://support.microsoft.com/kb/2877816
After installing this HotFix, this issue is resolved!!
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2YGUnANR7EUmHMh3kFU4hzY5Jviq_XoiozHeCY1jjPQbuaCg3u2qldW6GJOPn6zhNqi4bsn_kT4AFjH2lBxbE7OJCfrI_ODQkIKdeTjMSLU9b-LIyuBTpIEKiG-lXSaZ7Q45TyeElTgc/s1600/vary-header-working.png)
We can now play with Vary header along with Dynamic Content Compression module!!
No comments:
Post a Comment