是否可以禁用 ASP.NET 中的 browserCaps 功能?

发布于 2024-09-26 19:21:37 字数 210 浏览 4 评论 0原文

是否可以禁用 ASP.NET 中的 browserCaps 功能?

我希望我的网站能够可靠且完全按照我为所有浏览器定义的方式提供服务,无论其功能如何。

如果他们的浏览器不支持该网站,那就是他们的问题。我的网站不应该试图自我降级以适应已失效的客户。

当蜘蛛似乎运气不好时,这非常令人沮丧,我猜爬行该网站,获取该网站的较小版本,导致输出缓存为剥离的文件提供服务。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酸甜透明夹心 2024-10-03 19:21:37

您可以将 ClientTarget="uplevel" 放在页面指令或 Page.Init 中

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

,或者

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

另一个选项是添加 .browser 文件复制到您网站的 App_Browsers 文件夹(默认的 Asp.NET 文件夹)中。它应该使用正则表达式针对所有浏览器,并通过添加功能以某种方式禁用正常的浏览器检测。我只是用它来在 Safari 中以正确的方式呈现菜单控件,但我并不完全知道如何同时对所有输出执行此操作。

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.

小镇女孩 2024-10-03 19:21:37

我目前正在尝试的一个疯狂的解决方法是注入我们自己的 HttpCapabilityDefaultProvider,它返回一个静态 HttpBrowserCapability。诀窍是始终返回相同的功能对象,因此通过在使用 IE9 时调用 base.GetBrowserCapability,我们使用 Newtonsoft 创建序列化,并通过将此字符串保存在源中,我们可以构建一个类似 IE9 的功能对象,无论哪个浏览器发起请求。

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;
    }
}

然后在 Application_Start 中分配提供程序:

HttpCapabilitiesBase.BrowserCapabilitiesProvider = new CustomerHttpCapabilitiesProvider();

但这尚未经过真正测试,不确定此更改的具体影响是什么。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文