【发布时间】:2012-02-20 08:27:51
【问题描述】:
我有以下代码读取 userAgent 并根据使用 indexOf 匹配的值执行一些逻辑:
String userAgent;
userAgent = Request.UserAgent;
// If it's not IE
if (userAgent.IndexOf("MSIE") < 0)
{
return RedirectToAction("Index", "Home", new { area = "Dashboard" });
}
// If it's IE BUT ChromeFrame
else if(userAgent.IndexOf("ChromeFrame") > -1)
{
return RedirectToAction("Index", "Home", new { area = "Dashboard" });
}
// It's just IE
else
{
return View("ChromeFrame");
}
如果是 IE,那么它应该返回视图,或者如果它的 IE 但包含 ChromeFrame,那么它应该重定向并且它是另一个浏览器,那么它也应该重定向。
我认为问题出在代码的> 0 部分。比较信息的正确方法是什么?谢谢。
【问题讨论】:
-
你不应该以你已经得到的答案不再适用的方式更改代码......
标签: c# asp.net-mvc-3