简体   繁体   English

以编程方式将UserAgent从IE11更改为IE 9

[英]Change UserAgent programmatically from IE11 to IE 9

I have to open a Report using Crystal Report Viewer, when open on IE11 I got design issues but changing the user agent to IE9 will adjust the design of the report. 我必须使用Crystal Report Viewer打开报表,在IE11上打开时遇到了设计问题,但是将用户代理更改为IE9会调整报表的设计。 What is the solution that can be done to change the user agent string of my page, knowing that I don't want to change the web.config of the whole website. 知道我不想更改整个网站的web.config,可以采取什么解决方案来更改页面的用户代理字符串。 I need a help This is my Code: 我需要帮助这是我的代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="rpt.aspx.cs" Inherits="Reports_rpt" %>

<%@ Register Assembly="CrystalDecisions.Web" Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Report</title>
    <meta http-equiv="X-UA-Compatible" content="IE=9" />
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9" />
    <script type="text/javascript">
        if (version = /MSIE (\d+\.\d+)/.exec(navigator.userAgent)) {
            isIE = true;
            browserVersion = parseFloat(version[1]);
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div style="width: 800px; height: 700px; margin-left: auto; margin-right: auto;">
            <CR:CrystalReportViewer ID="rpt" runat="server" AutoDataBind="True" DisplayGroupTree="False"
                ToolPanelView="None" ToolbarImagesFolderUrl="~/aspnet_client/system_web/4_0_30319/CrystalReportWebFormViewer4/Images/ToolBar/" />
            <center>
                <asp:Label ID="lblMsg" runat="server" Style="display: block; color: orange; font-size: 15pt;" />
            </center>
        </div>
    </form>
</body>
</html>

From Micorsoft's site: 在Micorsoft的网站上:

  WebClient client = new WebClient ();

    // Add a user agent header in case the 
    // requested URI contains a query.

    client.Headers.Add ("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");

    Stream data = client.OpenRead (MyHTMLFile.html);
    StreamReader reader = new StreamReader (data);
    string s = reader.ReadToEnd ();
    Console.WriteLine (s);
    data.Close ();
    reader.Close ();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM