Is it possible to cache a page by Browser Version and/or some params
Yes. In your page: <%@ OutputCache Duration=’60’ VaryByParams=’abc;xyz’ VaryByCustom=’browsermajorversion’ %> In your global.asax file: VB.NET Public Overrides Function GetVaryByCustomString(context As HttpContext, custom As String) As String If custom.ToLower() = ‘browsermajorversion’ Then Dim browser As HttpBrowserCapabilities = context.Request.Browser Return browser.Browser + ‘ ‘ + browser.MajorVersion Else Return MyBase.GetVaryByCustomString(context, custom) End If End Function ’GetVaryByCustomString C# public override string GetVaryByCustomString(HttpContext context, string custom) { if (custom.ToLower() == ‘browsermajorversion’) { HttpBrowserCapabilities browser = context.Request.Browser; return browser.Browser + ‘ ‘ + browser.MajorVersion; } else { return base.GetVaryByCustomString(context, custom); } }
I want to Cache based on HTTP header .How can I do that
<%@OutputCache … VaryByHeader=’UserAgent’ %> or <%@ OutputCache … VaryByHeader=’Accept-Language’ %>
How to prevent client Cache? I want every client request get sent to the server even if it’s behind a proxy server and for any browser setting.
You can use tag <%@ OutputCache Duration=’0′ Location=’None’ VaryByParam=’none’ %> or VB.NET Response.Cache.SetCacheability(HttpCacheability.NoCache) C# Response.Cache.SetCacheability(HttpCacheability.NoCache);
How to make a page expire immediately in such a way that a warning message ‘This page has expired.’appears
Try the following: <%@ OutputCache location=’none’ %>
How to select all the Items from a listbox when the user selects a radio button
<asp:listbox id=’ListBox1′ runat=’server’ selectionmode=’Multiple’> <asp:listitem value=’Red’>Red</asp:listitem> <asp:listitem value=’Blue’>Blue</asp:listitem> <asp:listitem value=’Green’>Green</asp:listitem> <asp:listitem value=’White’>White</asp:listitem> </asp:listbox> <asp:radiobutton id=’RadioButton1′ runat=’server’ groupname=’selrb’ text=’Select All’ autopostback=’True’></asp:radiobutton> VB.NET Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged Dim lstItem As ListItem For Each lstItem In ListBox1.Items lstItem.Selected = True Next End Sub C# foreach (ListItem lstItem in ListBox1.Items) { lstItem.Selected = true; }