Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在ASP.NET MVC中为请求升级的IE6用户显示特殊页面_Asp.net_Internet Explorer_Internet Explorer 6 - Fatal编程技术网

如何在ASP.NET MVC中为请求升级的IE6用户显示特殊页面

如何在ASP.NET MVC中为请求升级的IE6用户显示特殊页面,asp.net,internet-explorer,internet-explorer-6,Asp.net,Internet Explorer,Internet Explorer 6,就像其他所有的网络开发人员一样,我也很沮丧,因为我的网站代码被黑客攻击而无法使用IE6。所以决定放弃对IE6的支持,礼貌地要求他们升级到IE7+或Firefox 您能建议我如何检测IE6用户并在ASP.NET MVC中显示显示升级详细信息的特殊页面吗 在服务器端编写脚本处理这个问题是个好主意吗?或者你建议使用jQuery这样的客户端脚本来处理这个问题吗?为IE 6显示完全不同的页面有点苛刻,除非你想阻止/重定向,否则不需要在服务器端验证 “礼貌”意味着您在客户端验证浏览器,并显示要升级的警报/提

就像其他所有的网络开发人员一样,我也很沮丧,因为我的网站代码被黑客攻击而无法使用IE6。所以决定放弃对IE6的支持,礼貌地要求他们升级到IE7+或Firefox

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


在服务器端编写脚本处理这个问题是个好主意吗?或者你建议使用jQuery这样的客户端脚本来处理这个问题吗?

为IE 6显示完全不同的页面有点苛刻,除非你想阻止/重定向,否则不需要在服务器端验证

“礼貌”意味着您在客户端验证浏览器,并显示要升级的警报/提醒消息。网站上的人基于(他们建议您在登录页顶部显示一条消息)


图片礼貌:

专门为IE6提供一个不同的非功能性页面将是一种可怕的做法。首先,如果你在英国,你很可能会触犯DDA,在几秒钟内(当然取决于你的情况),你真的不想阻止20-25%的用户使用你的网站

很多人被迫在工作中使用IE6。不必要地激怒他们并没有很好的商业意义

也就是说,没有理由让你的网站看起来完美。您可以检测到他们正在使用带有Request.UserAgent的IE6服务器端,并在主页顶部(或每页顶部)显示一条不显眼的消息,让用户知道他们的浏览器非常旧,您不再支持它。然后,您可以提供一个特定的IE6样式表(非常精简),或者如果IE6的呈现问题没有严重到使您的站点无法使用的程度,您就不必担心它们了


这些天,当我在互联网上工作时,我会额外收取支持IE6的费用。

您可以通过编码进行检测:

// ASP.net MVC C# example 
if (Request.Browser.Browser == "IE" && Request.Browser.Version.ConvertTo<float>() < 7.0)
{   
    // output message to urge user to upgrade to latest IE browser 
}
//ASP.net MVC#示例
if(Request.Browser.Browser==“IE”&&Request.Browser.Version.ConvertTo()<7.0)
{   
//输出消息,敦促用户升级到最新的IE浏览器
}

IMO中最简单的事情是创建一个操作过滤器属性。然后,您可以用它标记控制器(或添加到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,这将向他们显示一个页面,告诉他们他们有一个糟糕的旧浏览器。这给了他们升级的选择,但他们也可以
///选择继续。此检查仅在他们首次访问站点时进行。cookie还可以防止将来不必要的检查,因此不会减慢应用程序的速度。
/// 
公共类警告6属性:ActionFilterAttribute
{
公共覆盖无效OnActionExecuting(ActionExecutingContext filterContext)
{
var request=filterContext.HttpContext.request;
//当他们第一次访问该站点时,这将是真实的(如果他们清除cookie,将再次发生)
if(request.urlReferer==null&&request.Cookies[“browserChecked”]==null)
{
//第一次给老IE用户一个警告

如果(request.Browser.Browser.Trim().ToUpperInvariant().EqualsExact(“IE”)和&request.Browser.MajorVersion我在IE8及以下版本出现问题时遇到了这个答案。我希望用户使用IE9或更高版本,但IE9上的兼容模式显示为IE7

因此,添加到Steve Potters的答案,并受以下链接的启发-

我把代码改成了

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

        if (request.UrlReferrer == null)
        {
            if (request.Browser.Browser.Trim().ToUpperInvariant().Equals("IE") && request.Browser.MajorVersion <= 8)
            {
                var useragent = request.Headers.GetValues("User-Agent"); 
                if (useragent != null) isIe9Compatible = useragent[0].Contains("Trident/5.0");
                if (!isIe9Compatible) filterContext.Result = new ViewResult {ViewName = "_InternetExplorerOldWarning"};
            }
        }
    }
}
public类WarnAboutIeAttribute:ActionFilterAttribute
{
公共覆盖无效OnActionExecuting(ActionExecutingContext filterContext)
{
var request=filterContext.HttpContext.request;
var isIe9Compatible=false;
if(request.urlReferer==null)
{

if(request.Browser.Browser.Trim().ToUpperInvariant().Equals(“IE”)和&request.Browser.MajorVersion非常干净的解决方案。非常感谢。不需要完整的代码,但访问浏览器的信息(
request.Browser.Browser
request.Browser.MajorVersion
)才是重点。干得好。
public class WarnAboutIeAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        var request = filterContext.HttpContext.Request;
        var isIe9Compatible = false;

        if (request.UrlReferrer == null)
        {
            if (request.Browser.Browser.Trim().ToUpperInvariant().Equals("IE") && request.Browser.MajorVersion <= 8)
            {
                var useragent = request.Headers.GetValues("User-Agent"); 
                if (useragent != null) isIe9Compatible = useragent[0].Contains("Trident/5.0");
                if (!isIe9Compatible) filterContext.Result = new ViewResult {ViewName = "_InternetExplorerOldWarning"};
            }
        }
    }
}