Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to disable the browserCaps functionality in ASP.NET?

Is it possible to disable the browserCaps functionality in ASP.NET?

I wish my site to be served reliably and exactly as I have it defined to all browsers regardless of their capabilities.

If their browser can't support the site, that's their problem. My site should not be some how attempting to degrade itself to accommodate the defunct client.

This is very frustrating when it seems to have the bad luck of spiders I guess crawling the site, getting the lesser version of the site causing output caching to serve the stripped file.

like image 830
Chris Marisic Avatar asked Oct 06 '10 12:10

Chris Marisic


People also ask

How to prevent browser back button in ASP net?

Solution 3: Disable the Back button completely How simple? Just add onload=”window. history. forward();” to the <body> tag in the page(s) that you don't want the user to be able to click Back to.

What ASP net object is used to determine browser information?

The old method: Determining browser type in ASP Traditional ASP applications used the Browser Capabilities object that resides in the \system32\inetsrv\browscap. dll DLL. This object takes the User Agent string that a browser sends to a website and compares it to a list of simple wildcard expressions in the browscap.


2 Answers

You can put ClientTarget="uplevel" in the page directive or in the Page.Init

<%@ Page ClientTarget="uplevel" ...... %>

or

Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) _
        Handles Me.Init
    Page.ClientTarget = "uplevel"
End Sub

Another option is to add a .browser file to your site, in the folder App_Browsers (a default Asp.NET folder). It should target all browser with a regex expression and somehow disable the normal browser detection by adding capabilities. I'm only using this to render the Menu control the right way in Safari but I don't exactly know how to do this for all output at once.

like image 117
Willem Avatar answered Nov 02 '22 12:11

Willem


An insane workaround I'm currently trying out is to inject our own HttpCapabilitiesDefaultProvider which returns a static HttpBrowserCapabilities. The trick then is to always return the same capabilities object, so by calling base.GetBrowserCapabilities while using IE9, we've used Newtonsoft to create a serialization, and by saving this string in the source, we can build an IE9 like capabilities object regardless of what browser initiated the request.

public class CustomerHttpCapabilitiesProvider : HttpCapabilitiesDefaultProvider
{
    private const string m_IE9Definition = "{\r\n  \"$type\": \"System.Web.Mobile.MobileCapabilities, System.Web.Mobile\",\r\n  \"UseOptimizedCacheKey\":..... ";
    private readonly static Lazy<MobileCapabilities> m_Capabilities = new Lazy<MobileCapabilities>(() => JsonConvert.DeserializeObject<MobileCapabilities>(m_IE9Definition), true);

    public override HttpBrowserCapabilities GetBrowserCapabilities(HttpRequest request)
    {
        return m_Capabilities.Value;
    }
}

and then assigning the provider in Application_Start:

HttpCapabilitiesBase.BrowserCapabilitiesProvider = new CustomerHttpCapabilitiesProvider();

This hasn't really been tested however, unsure of what exactly is the impact of this change.

like image 34
Svend Avatar answered Nov 02 '22 11:11

Svend