asp.net addresses browser compatibility issues with server side code
- 2020-05-07 19:26:40
- OfStack
Use the code to determine which version of the browser the client is using
Response. Write (Request. ServerVariables [" HTTP_USER_AGENT] "); (this seems to work on ASP as well.)
or
Response.Write(Request.UserAgent);
Mine is IE7 output:
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SE 1.X; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; SE 1.X)
Google browser output:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/3.0.195.38 Safari/532.0
Write a public method call in the background (reference to be added)
Response. Write (Request. ServerVariables [" HTTP_USER_AGENT] "); (this seems to work on ASP as well.)
or
Response.Write(Request.UserAgent);
Mine is IE7 output:
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SE 1.X; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; SE 1.X)
Google browser output:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/3.0.195.38 Safari/532.0
Write a public method call in the background (reference to be added)
public static int getBrowser()
{
string BrowserInfo = HttpContext.Current.Request.UserAgent;
if (BrowserInfo.Contains("MSIE 7.0"))
{//IE7
return 1;
}
else if (BrowserInfo.Contains("MSIE 6.0"))
{//IE6
return 2;
}
else if (BrowserInfo.Contains("Firefox"))
{//IE6
return 3;
}
else if (BrowserInfo.Contains("Chrome"))
{// Google
return 4;
}
return 5;
}