We help IT Professionals succeed at work.

Determine if client side browser used is IE 11

ROBERT MECHLER
on
RDLC has issues when running on Internet Explorer 11. How do I identify if a client side computer connected to our website has IE 11. I've read things that say MS tries to hide this by calling it Trident and then vs 11.

Javascript, Jquery, C# all okay for examples
Comment
Watch Question

ste5anSenior Developer

Commented:
There is no reliable way. Cause it requires client-side JavaScript, which results can easily be spoofed.

How do you open your reports?
Architect - Coder - Mentor
Commented:
Hi,
You can read about IE11 user-agent header values.
For getting the values, you can use HttpRequest.UserAgent Property

https://docs.microsoft.com/en-us/dotnet/api/system.web.httprequest.useragent?redirectedfrom=MSDN&view=netframework-4.8#System_Web_HttpRequest_UserAgent
One I've used for IE11 for quite a while, though I haven't really had to for a few years.
As ste5an pointed out, not guaranteed as it can easily be spoofed, but for your purposes should be more than sufficient.

Regex.IsMatch(HttpContext.Current.Request.UserAgent, "(?=.*Windows NT)(?=.*rv:11)(?=.*Trident)", RegexOptions.IgnoreCase))

Open in new window

ROBERT MECHLERProgramming manager

Author

Commented:
ste5an

        private void BindPortfolioAllocationReport(string reportOption)
        {
            DataSet portfolioAllocation = ReportsModel.GetPortfolioDistributions(Convert.ToInt32(Session["SessionID"].ToString()), Session["IPAddress"].ToString());
            if (portfolioAllocation != null)
            {
                if (portfolioAllocation.Tables.Count > 0)
                {
                    if (portfolioAllocation.Tables["AssetType"] != null)
                    {
                        for (int i = 0; i < portfolioAllocation.Tables["AssetType"].Rows.Count; i++)
                        {
                            portfolioAllocation.Tables["AssetType"].Rows[i]["MarketValue"] = Math.Round(Convert.ToDecimal(portfolioAllocation.Tables["AssetType"].Rows[i]["MarketValue"]), 2, MidpointRounding.AwayFromZero);
                        }
                        ReportDataSource allocationDatasource = null;
                        if (reportOption == "Investment")
                        {
                            portfolioAllocation.Tables["AssetType"].DefaultView.RowFilter = "AssetTypes_Id = 0";
                            allocationDatasource = new ReportDataSource("PortfolioAllocationDataSet", portfolioAllocation.Tables["AssetType"].DefaultView);
                        }
                        else if (reportOption == "Industry")
                        {
                            portfolioAllocation.Tables["AssetType"].DefaultView.RowFilter = "AssetTypes_Id = 1";
                            allocationDatasource = new ReportDataSource("PortfolioAllocationDataSet", portfolioAllocation.Tables["AssetType"].DefaultView);
                        }
                        tnetReportViewer.LocalReport.DataSources.Clear();
                        tnetReportViewer.LocalReport.DataSources.Add(allocationDatasource);
                        tnetReportViewer.LocalReport.ReportPath = Server.MapPath(".") + "\\PortfolioAllocation.rdlc";
                        tnetReportViewer.LocalReport.EnableExternalImages = true;
                        Color color = System.Drawing.ColorTranslator.FromHtml(ConfigurationManager.AppSettings["ReportToolbarColor"] != null ? ConfigurationManager.AppSettings["ReportToolbarColor"].ToString() : string.Empty);
                        tnetReportViewer.BackColor = color;
                        ReportParameter[] rp = new ReportParameter[7];
                        rp[0] = new ReportParameter("ImagePath", "file:////" + Server.MapPath("~/Images/Report_Image.bmp"));
                        if (reportOption == "Investment")
                        {
                            rp[1] = new ReportParameter("ReportHeader", "Portfolio Allocation");
                        }
                        else
                        {
                            string _sSuggestedName = String.Empty;
                            _sSuggestedName = "EquityAllocationbyIndustry";
                            tnetReportViewer.LocalReport.DisplayName = _sSuggestedName;
                            rp[1] = new ReportParameter("ReportHeader", "Equity Allocation by Industry");
                        }
                        rp[2] = new ReportParameter("ReportHeaderColor", ConfigurationManager.AppSettings["RportHeaderColor"] != null ? ConfigurationManager.AppSettings["RportHeaderColor"].ToString() : string.Empty);
                        string PortfolioCodeName = string.Empty;
                        if (portfolioAllocation.Tables["Portfolio"] != null)
                        {
                            if (portfolioAllocation.Tables["Portfolio"].Rows.Count > 0)
                            {
                                PortfolioCodeName = portfolioAllocation.Tables["Portfolio"].Rows[0]["Code"].ToString() + " - " + portfolioAllocation.Tables["Portfolio"].Rows[0]["Name"].ToString();
                            }
                        }
                        rp[3] = new ReportParameter("PortfolioCodeName", PortfolioCodeName);
                        string CashInvestment = string.Empty;
                        rp[4] = new ReportParameter("CashInvestment", CashInvestment);
                        string clientDatetime = Session["ClientDatetime"].ToString(); //Convert.ToString(Session["ClientDatetime"],"MM-dd-yyyy hh:mm tt");
                        rp[5] = new ReportParameter("LocalDateTime", clientDatetime);
                        rp[6] = new ReportParameter("ReportHeaderText", ConfigurationManager.AppSettings["RportHeaderText"] != null ? ConfigurationManager.AppSettings["RportHeaderText"].ToString() : string.Empty);
                        this.tnetReportViewer.LocalReport.SetParameters(rp);
                        string strFormat = ConfigurationManager.AppSettings["ExcludedExports".ToString()];
                        FieldInfo info;
                        foreach (RenderingExtension extension in tnetReportViewer.LocalReport.ListRenderingExtensions())
                        {
                            if (strFormat.Contains(extension.Name))
                            {
                                info = extension.GetType().GetField("m_isVisible", BindingFlags.Instance | BindingFlags.NonPublic);
                                info.SetValue(extension, false);
                            }
                        }
                        LinkToTop.Visible = true;
                    }
                }
            }
            else
            {
                this.tnetReportViewer.Visible = false;
                MessageDiv.Attributes.Add("Class", "red-mess");
                MessageDiv.Style.Add("display", "block");
                MessageLabel.Text = "No Records Available!!!";
            }
        }

Open in new window


I'll try the other methods. Not worried about spoofing. I will most likely just identify it and give a warning message suggesting a different browser. I heard that IE 11 has an end of life of 12/31/2020. Some have suggested using the dll from 2012 or higher for the reportwriter but no clear cut full answers there. Thanks.
ROBERT MECHLERProgramming manager

Author

Commented:
Eduard pointed me in what I think will be a useful direction with some pertinent hyperlinks. Snar0001 also alluded to the useragent and I will most likely try his as well.  Thanks.
Eduard GherguArchitect - Coder - Mentor

Commented:
Hi,
My pleasure! Please, let me know if you need more help.
ROBERT MECHLERProgramming manager

Author

Commented:
This code works for me.
            string WebBrowserName = HttpContext.Current.Request.Browser.Browser;
            string WebBrowserCapabilities = HttpContext.Current.Request.Browser.Capabilities[""].ToString();
            string WebIE11 = WebBrowserName + "-" + WebBrowserCapabilities;
            if (WebIE11.Contains("IE") && WebIE11.Contains("Trident/7.0") || WebIE11.Contains("InternetExplorer"))
            {
                ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('If you run a newer browser such as Chrome or Microsoft Edge, all functions of the website will work normally.');", true);
            }

Open in new window


There may some weakness but for every IE 11 we worked with it successfully identified if IE 11 was in use. I set it so the program would run after the popup so they could access a lot more of application that didn't use RDLC.  

I most likely will switch to a jquery dialog to make it a little better looking.