Lo más fácil OMI es crear un atributo del filtro acción. Luego puede etiquetar sus controladores con él (o agregarlo a los filtros globales en MVC3).
Aquí es el atributo: cheques
/// <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"));
}
}
}
este atributo para IE6, y si está presente, se representa la vista "InternetExplorerOldWarning", que hay que crear. Solo presenta esta advertencia una vez mediante el uso de una cookie. Por supuesto, podrías modificar eso como quieras. En mi opinión, les di enlaces para actualizar o descargar otros navegadores. También les di la oportunidad de continuar con IE6. Échale un vistazo:
<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>
Solución muy limpia. Muchas gracias. – Gopinath
No necesitó el código completo, pero acceder a la información del navegador ('request.Browser.Browser' y' request.Browser.MajorVersion') era el punto. Buen trabajo. – nrod