Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
471 views
in Technique[技术] by (71.8m points)

asp.net - Internet explorer 11 detection on server side

We all know that IE11 detection does not work with server side languages because Microsoft has removed the IE/MSIE browser indication and now is fully "Mozilla".

I also know that doing browser detection/version is risky but has served us all well in the past.

some requirements for a website are things like:

must work with certain version of firefox and above must work with certain version of chrome and above must work with certain version of safari's (some below and some newer) must work with IE >= 8

so here is the problem... IE11 indicates on my list that it is not supported. I want to support it from the web side of things on the server (ASP.NET/MVC)

it is not clear exactly how to detect this from the server side. Does anyone know how?

this is the user agent now being shown in IE 11:

"Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"

rv:11.0 tells us its IE11 however doing a parse on that will still mean that for example, it could be chrome of a certain version that is not supported in such a requirement or even firefox.

so, what is the best way here to see if it is indeed IE 11 or higher?

I am not so sure about searching from "Trident" and onwards because I don't know if other browsers use that or not.

any direction is welcomed.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use a Regular Expression like:

Regex.IsMatch(this.Request.UserAgent, @"Trident/7.*rv:11")

Trident is the name of the rendering engine IE uses. Some other applications also use the Trident engine, as you can see in the Wikipedia article. But it shouldn't be a problem to search for Trident in the User Agent, since no other major browsers use Trident.

Only IE11 uses Trident version 7 so if you search for Trident/7 with the regex, it should find IE11.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...