सबसे आसान बात IMO एक कार्रवाई फिल्टर विशेषता तैयार करना है। फिर आप अपने नियंत्रकों को इसके साथ टैग कर सकते हैं (या एमवीसी 3 में वैश्विक फ़िल्टर में जोड़ें)।
यहाँ विशेषता है: 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" दृश्य है, जिसे आप बनाने के लिए बना देता है। यह केवल कुकी का उपयोग करके इस चेतावनी को प्रस्तुत करता है। आप निश्चित रूप से ट्विक कर सकते हैं कि आप चाहते हैं। मेरे विचार में, मैंने उन्हें अन्य ब्राउज़रों को अपडेट या डाउनलोड करने के लिए लिंक दिए। मैंने उन्हें आईई 6 के साथ जारी रखने का अवसर भी दिया। इसे देखें:
<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>
स्रोत
2011-02-04 17:48:07
बहुत साफ समाधान। बहुत बहुत धन्यवाद। – Gopinath
को पूरा कोड की आवश्यकता नहीं थी लेकिन ब्राउज़र की जानकारी तक पहुंच ('request.Browser.Browser' और' request.Browser.MajorVersion') बिंदु था। बहुत बढ़िया। – nrod