locked
browser detection RRS feed

  • Question

  • User1024191908 posted

    I have a third party web user control and it seems that it only generates some javascript code if it detects some specific browser(e.g IE 11)

    so how can I fake it so the user control thinks it is IE 11 not chrome or firefox?

    Saturday, April 21, 2018 7:29 AM

Answers

  • User1024191908 posted

    I found that using a class that inherits IHTTPMODULE and then adding an event handler for Begin_Request() I can change the user agent.

    public class UserAgentHandler : IHttpModule
        {
            public void Init(HttpApplication app)
            {
                app.BeginRequest += new EventHandler(BeginReq);
            }
    
            public  void Dispose()
            {
    
            }
    
            public void BeginReq(object sender,EventArgs e)
            {
    
                NameValueCollection headers = HttpContext.Current.Request.Headers;
                headers.Remove("User-Agent");
                headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36");
            }
        }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 21, 2018 10:15 AM

All replies

  • User1120430333 posted

    https://jsfiddle.net/311aLtkz/

    You check to see if it's IE and then do something.

    Saturday, April 21, 2018 8:27 AM
  • User1024191908 posted

    I found that using a class that inherits IHTTPMODULE and then adding an event handler for Begin_Request() I can change the user agent.

    public class UserAgentHandler : IHttpModule
        {
            public void Init(HttpApplication app)
            {
                app.BeginRequest += new EventHandler(BeginReq);
            }
    
            public  void Dispose()
            {
    
            }
    
            public void BeginReq(object sender,EventArgs e)
            {
    
                NameValueCollection headers = HttpContext.Current.Request.Headers;
                headers.Remove("User-Agent");
                headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36");
            }
        }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 21, 2018 10:15 AM