检查浏览器是否为镶边或边缘 [英] check whether browser is chrome or edge
问题描述
我的当前网站只能在Chrome浏览器中运行,为此我已按照以下方式进行检查:
if(Request.Browser .Browser ==Chrome)
{
//允许
}
但是对于 Edge ,它也会以仅限Chrome浏览器
。
如何才能允许仅通过Chrome浏览器访问?
<您可以检查用户代理并查看它是否为Microsoft Edge,因为Microsoft Edge包含
Edge / version
在它的用户代理字符串中。 //根据您正在处理的内容在某处获取用户代理
userAgent = Request.UserAgent;
if(userAgent.IndexOf(Edge)> -1)
{
//也许客户端的浏览器是Microsoft Edge
}
边缘用户代理字符串示例
Mozilla / 5.0(X11; CrOS x86_64 6783.1.0)AppleWebKit / 537.36(KHTML,如Gecko)Edge / 12.0
最后,我建议在浏览器上使用功能检测,而不是基于用户代理进行操作。
My current website runs only in Chrome browser, to do this I have checked in following way
if (Request.Browser.Browser == "Chrome")
{
// Allow
}
But for Edge as well it is returning as "Chrome"
only.
How can I allow access from only Chrome browser?
You can check user-agent and see whether it is Microsoft Edge or not because Microsoft Edge contains Edge/version
in it's user-agent string.
//get user agent somehow here based on what you are working on
userAgent = Request.UserAgent;
if (userAgent.IndexOf("Edge") > -1)
{
// maybe client's browser is Microsoft Edge
}
sample of Edge user-agent strings
Mozilla/5.0 (X11; CrOS x86_64 6783.1.0) AppleWebKit/537.36 (KHTML, like Gecko) Edge/12.0
At the end I suggest to use feature detection on browser instead of acting based on user-agent.
这篇关于检查浏览器是否为镶边或边缘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!