I have a web application which has alot of widgests/page in it. Certain widgets I want to block when opened in Safari and display some sort of message if anyone tries to open the webapp from Safari browser. Below is the code I have written.
public class BlockFromSafari : System.Web.Mvc.ActionFilterAttribute
{
// runs just before the action is executed
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var browserType = filterContext.HttpContext.Request.Browser.Browser;
base.OnActionExecuting(filterContext);
if (browserType.Contains("Safari"))
{
// Redirect the user accordingly
filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { { "controller", "Security" }, { "action", "Safari" } });
}
}
}
Kindly note that I have applied this filter on the all the Action Method which I want
public ActionResult Safari()
{
return Content("This is SAFARI!!");
}
Current Behaviour:
If I open the website and visit the corresponding URL, in Chrome in WindowsPC page opens fine, where as if I open in Safari Browser in Windows PC I get redirected to "This is SAFARI content page".
If I open the website and visit the corresponding URL, in Chrome in Mac PC page opens fine, where as if I open in Safari Browser in Mac PC I get redirected to "This is SAFARI content page"
So far so good. Now here is the problem
Issue: If I open the website and visit the corresponding URL, in Chrome in Mobile device or Ipad page still displays "This is SAFARI" ideally I expected the same behaviour as in PC. Please guide me.
Expected Behaviour:
Mobile Device-Chrome - Should open fine
Mobeil Devive-Safari - "This is SAFARI" should be displayed
Interesting Read Chrome Treated as Safari