2

我想知道是否有某种方法可以“强制”用户更新用户的网络浏览器。

例如,如果用户进入我的网站并且他或她使用的是旧版本的浏览器,则通常隐藏的页面区域将被显示出来。该显示区域将包含浏览器更新建议和指向外部页面的超链接,用户可以在其中下载用户浏览器的新版本或更新当前版本。

具体来说,以下是我需要指导的目标的两个方面:

  1. 如何识别浏览器及其版本,以及
  2. 如何显示特定于用户当前使用的浏览器的隐藏区域。(也许每种常见的浏览器都会有一个区域,所以问题是如何显示相关区域。)
4

2 回答 2

2

在我的研究中,我遇到了这个网站,它提供了一个基于 JavaScript 的小型通知组件:

http://browser-update.org/index.html

这正是我一直在寻找的。

于 2013-04-13T17:46:47.550 回答
1

例如,您可以在 ActionFilterAttribute 中执行此操作。例如,它可能如下所示:

public class WarnAboutOldBrowserAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        var request = filterContext.HttpContext.Request;

        //check if it browser warning was already checked
        if (request.Cookies["checked"] != null)
        {
             return;
        }
        //exmaple is for IE 6
        if (request.Browser.Browser.Trim().ToUpperInvariant().EqualsExact("IE") && request.Browser.MajorVersion <= 6)
        {
          filterContext.Controller.ViewData["RequestedUrl"] = request.Url.ToString();

          filterContext.Result = new ViewResult { ViewName = "OldBrowserWarning" };
        }
        //add cookie for caching
        filterContext.HttpContext.Response.AppendCookie(new HttpCookie("checked", "true"));
        }

    }
}

当然,您还必须添加一个名为“OldBrowserWarning”的视图来向用户显示信息。

其他方法是在 _Layout.cshtml 中添加警告,并在上面的代码中在 ViewBag 中设置正确的标志

于 2013-04-06T13:24:55.853 回答