2009-09-16 3 views
12

다른 모든 웹 개발자와 마찬가지로 IE6에서 작동하도록 사이트 코드를 해킹하는 것에 좌절감을 느낍니다. IE 6을 열고 정중하게 IE 7+ 또는 Firefox로 업그레이드하도록 요청하십시오.ASP.NET MVC에서 업그레이드를 요청하는 IE6 사용자를위한 특별 페이지를 표시하는 방법

IE6 사용자를 감지하고 ASP.NET MVC의 업그레이드 세부 정보를 표시하는 특별한 페이지를 표시하는 방법을 제안 해 주시겠습니까?

이것을 서버 측 스크립팅에서 처리하는 것이 좋습니다. 또는 이것을 처리하기 위해 jQuery와 같은 클라이언트 측 스크립트를 사용하도록 권장합니까?

답변

20

가장 쉬운 일이 IMO 액션 필터 속성을 만드는 것입니다. 그런 다음 컨트롤러에 태그를 붙이거나 MVC3의 전역 필터에 추가 할 수 있습니다.

다음은 속성의 : IE6에 대한

/// <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")); 
     } 

    } 
} 

이 속성을 확인하고, 존재 있다면, 그것은 당신이 만들 수있는 "InternetExplorerOldWarning"보기를 렌더링합니다. 이 경고는 쿠키를 사용하여 한 번만 표시됩니다. 물론 원하는대로 조정할 수 있습니다. 필자는 다른 브라우저를 업데이트하거나 다운로드 할 수있는 링크를 제공했다. 나는 또한 그들에게 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> 
+1

매우 깨끗한 용액. 고마워. – Gopinath

+0

전체 코드는 필요 없지만 브라우저 정보 ('request.Browser.Browser' 및'request.Browser.MajorVersion')에 액세스하는 것이 핵심이었습니다. 잘 했어. – nrod

1

IE 6에서 완전히 다른 페이지를 보여주는 것은 가혹한 IMHO입니다. 차단/리다이렉션을 원하지 않는 한 서버 측에서이를 검증 할 필요가 없습니다.

"Polely"은 클라이언트 측에서 브라우저의 유효성을 검사하고 업그레이드하라는 경고/알림 메시지를 표시한다는 것을 의미합니다. 사람들은 stoplivinginthepast.com have build a standard logic to do thisconditional comments을 기반으로합니다 (방문 페이지 상단에 메시지를 표시하는 것이 좋습니다).

http://www.stoplivinginthepast.com/get-the-code/ http://www.stoplivinginthepast.com/wp-content/uploads/2009/02/warninggrab.jpg

이미지 제공 : http://www.stoplivinginthepast.com/

2

특히 IE6에 다른 ​​비 기능 페이지를 제공하는 끔찍한 연습이 될 것입니다. 우선, 영국에 계시다면 (물론 상황에 따라) 몇 초 동안 DDA에 불만을 품을 것입니다. 실제로 사이트를 사용하는 사용자의 20-25 %를 막고 싶지는 않습니다 .

많은 사람들이 직장에서 IE6을 사용해야합니다. 불필요하게 그들을 화나게하는 것은 좋은 사업 감각을 만들지 않습니다.

그렇다고해서 사이트를 완벽한 픽셀로 보이게 할 이유는 없습니다. Request.UserAgent를 사용하여 IE6 서버 측을 사용하고 있으며 홈 페이지 상단 (또는 모든 페이지 상단)에 눈에 잘 띄지 않는 메시지를 표시하여 사용자가 자신의 브라우저가 매우 오래되어서 ' 더 이상 지원하지 마십시오. 그런 다음 특정 IE6 스타일 시트 (매우 잘린)를 제공하거나 IE6의 렌더링 문제가 사이트를 사용할 수 없게 만들 정도로 심각하지 않은 경우에만 문제를 해결할 수 있습니다.

요즘 인터넷 작업을 할 때 IE6을 지원하기 위해 추가 비용을 부과합니다.

13

당신은 코딩에서 검출 할 수

// 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 
} 
0

내가 IE8 이하로 문제를 가지고이 대답을 발견했습니다. 사용자가 IE9 이상을 사용하고 IE9에서 호환 모드를 사용하여 IE7로 표시하길 원했습니다.

그래서 Steve Potters에 대한 답변을 추가하고 다음 링크 - http://social.msdn.microsoft.com/Forums/vstudio/en-US/ae715fd2-1ddd-46f7-8c26-9aed6b2103f1/how-to-detect-compatibility-mode-in-ie-any-version?forum=netfxjscript에서 영감을 얻었습니다.

나는 누군가 도움이되기를 바랍니다에 추가

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"}; 
      } 
     } 
    } 
} 

에 내 코드를 변경했습니다.

관련 문제