gpt4 book ai didi

asp.net - 如何为 IE6 用户显示特殊页面,要求他们在 ASP.NET MVC 中升级

转载 作者:行者123 更新时间:2023-12-04 00:04:19 25 4
gpt4 key购买 nike

就像所有其他 Web 开发人员一样,我对破解我的网站代码以使用 IE 6 感到沮丧。因此决定放弃对 IE 6 的支持并礼貌地要求他们升级到 IE 7+ 或 Firefox。

你能建议我如何检测 IE6 用户并显示一个特殊页面,显示 ASP.NET MVC 中的升级详细信息吗?

在服务器端脚本中处理这个是个好主意吗?或者您是否建议使用任何客户端脚本(如 jQuery)来处理此问题?

最佳答案

IMO 最简单的事情是创建一个 Action 过滤器属性。然后你可以用它标记你的 Controller (或添加到 MVC3 中的全局过滤器)。

这是属性:

/// <summary>
/// If the user has IE6, this will present them with a page that tells them they have a crappy old browser. It gives them options to upgrade but they can also
/// choose to proceed anyway. This check is done only when they first visit the site. A cookie also prevents unnecessary future checks, so this won't slow the app down.
/// </summary>
public class WarnAboutIE6Attribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var request = filterContext.HttpContext.Request;
//this will be true when it's their first visit to the site (will happen again if they clear cookies)
if (request.UrlReferrer == null && request.Cookies["browserChecked"] == null)
{
//give old IE users a warning the first time
if (request.Browser.Browser.Trim().ToUpperInvariant().EqualsExact("IE") && request.Browser.MajorVersion <= 6)
{
filterContext.Controller.ViewData["RequestedUrl"] = request.Url.ToString();

filterContext.Result = new ViewResult { ViewName = "InternetExplorerOldWarning" };
}

filterContext.HttpContext.Response.AppendCookie(new HttpCookie("browserChecked", "true"));
}

}
}

此属性检查 IE6,如果它存在,它将呈现您必须创建的“InternetExplorerOldWarning” View 。它仅通过使用 cookie 显示一次此警告。你当然可以随意调整。在我看来,我给了他们更新或下载其他浏览器的链接。我还给了他们继续使用 IE6 的机会。检查一下:
            <h3>
Your Internet Explorer is Outdated</h3>
<div class="warning">Your version of Internet Explorer is a bit too old and unfortunately won't work well with this site.</div>
<p>Have no fear. You have options and in just a few minutes you can be rocking out in our app:</p>
<ul>
<li>If you have FireFox, Safari, or Google Chrome already on your computer use one of them for Takeoff instead.</li>
<li>Upgrade to the <a href="http://www.microsoft.com/windows/internet-explorer/worldwide-sites.aspx">latest Internet Explorer.</a> You can download and install right away. Even Microsoft recommends you do this.</li>
<li>Download an Internet Explorer alternative. We recommend <a href="http://www.mozilla.com/en-US/firefox/firefox.html">FireFox</a>, <a href="http://www.apple.com/safari/download/">Safari</a>, or <a href="http://www.google.com/chrome">Google Chrome</a>. Choose one or all because each is great!</li>
</ul>

<p>This warning page will only show once. If you really want to use Takeoff with your current Internet Explorer, we won't stop you. But beware, it will probably look like garbage!</p>
<p>Whatever dude, I want to <a href="@ViewData["RequestedUrl"] ">my old, insecure, scary, dangerous version</a> of Internet Explorer.</p>

</div>

关于asp.net - 如何为 IE6 用户显示特殊页面,要求他们在 ASP.NET MVC 中升级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1431360/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com