Filter:
1 /// <summary>
/// 检测是否是手机访问
/// </summary>
public class IsMobileFilter : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
System.Web.HttpBrowserCapabilitiesBase myBrowserCaps = filterContext.HttpContext.Request.Browser;
bool flag = myBrowserCaps.IsMobileDevice;
if (flag)
{
string urls = "www.baidu.com";
if (!string.IsNullOrEmpty(urls))
{
urls = urls.Contains("http") ? urls.Trim() : "http://" + urls.Trim();
filterContext.Result = new RedirectResult(urls);
}
else
{
base.OnActionExecuting(filterContext);
}
}
else
{
base.OnActionExecuting(filterContext);
}
}
}     在FilterConfig中注册全局Filter    
      public static void RegisterGlobalFilters(GlobalFilterCollection filters)
 {
  filters.Add(new IsMobileFilter());
 }

  

MVC4 Filter 验证客户端访问类型(移动端、PC端)的更多相关文章

  1. javascript检测客户端环境是否是pc端

    //isPC(): 检测客户端环境是否是pc端 function isPC(){ let userAgent = navigator.userAgent; let agents = ["An ...

  2. js 设备判断(移动端pc端 安卓ios 微信)

    苹果安卓判断 $(function () { var u = navigator.userAgent, app = navigator.appVersion; var isAndroid = u.in ...

  3. 移动端&PC端CSS样式兼容代码

    CSS样式兼容代码 1.禁止选中复制文本 *{ user-select: none; -moz-user-select: none; -ms-user-select: none; -webkit-us ...

  4. REM布局计算,移动端,pc端有兼容性)

    rem布局计算(移动端,pc端有兼容性) <!DOCTYPE html> <html> <head lang="en"> <script& ...

  5. js -- 移动端pc端自动切换

    1. 判断浏览器类型 浏览器判断使用的github开源项目current-device,下面是地址: https://github.com/matthewhudson/current-device 在 ...

  6. Charles如何抓取https请求-移动端+PC端

    Charles安装完成,默认只能抓取到http请求,如果查看https请求,会显示unkonw或其它之类的响应.所以需要先进行一些配置,才能抓取到完整的https请求信息.下面针对PC端和手机端抓包的 ...

  7. socketserver和socket的补充(验证客户端合法性)

    一.socket的补充 1.参数 socket.socket(family=AF_INET,type=SOCK_STREAM,proto=0,fileno=None) 参数说明: family 地址系 ...

  8. 判断pc端还是移动,并给移动加上其它的样式文件方法

      所有移动端PC端 按 640 进行排版 body, html { width: %; height: %; overflow: hidden; background-color: #; } bod ...

  9. React.js 入门与实战之开发适配PC端及移动端新闻头条平台课程上线了

    原文发表于我的技术博客 我在慕课网的「React.js 入门与实战之开发适配PC端及移动端新闻头条平台」课程已经上线了,文章中是目前整个课程的大纲,以后此课程还会保持持续更新,此大纲文档也会保持更新, ...

随机推荐

  1. 【android】新手容易遇到的[error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'.]Theme出错的问题

    一.概述 近期刚接手了一个项目,开发工具为eclipse,由于版本较低,且考虑到如果转android studio项目的话,会其他人的维护带来困难,所以想着还是维护项目原来的开发环境吧. 但是导入项目 ...

  2. Load Mental Ray in Maya 2015

    In Maya 2015, we usually use mental ray to render our model, some new users may not see the mental r ...

  3. JAVA生成二维码图片代码

    首先需要导入 QRCode.jar 包 下载地址看这里   http://pan.baidu.com/s/1o6qRFqM import java.awt.Color;import java.awt. ...

  4. 20个有用的jq弹窗

    链接地址:http://www.ffpic.com/zixun/20-useful-jquery-modal-plugins.html 推荐:jQuery.bPopup.js

  5. [转]linux援救模式:linux rescue使用详细图解

    网上很多网友问怎么进rescue 模式,不知道怎么用rescue来挽救系统.  现在我来图解进入rescue (示例系统为RHEL 3) 1.用安装光盘或者硬盘安装的方式进入安装界面,在shell 中 ...

  6. MacPort 的使用

    MacPorts 的安装和使用   官网下载最版本的 安装包   自动安装  可能会出现很慢的情况   设置环境变量   vim ~/.bash_profile      i  插入修改  :wq 保 ...

  7. ngrok访问外网

    1. 外网映射工具介绍 windows用户: 1,下载windows版本的客户端,解压到你喜欢的目录2,在命令行下进入到path/to/windows_386/下3,执行 ngrok -config= ...

  8. 为Eclipse安装主题插件

    方法2:通过站点更新 eclipse:Help->Install New Software->Work with:Update Site -http://eclipse-color-the ...

  9. IOS第18天(1,核心动画layer, 旋转,缩放,平移,边框,剪裁,圆角)

    ****动画效果 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [UIView animateWithDurat ...

  10. 【iCore3 双核心板_ uC/OS-III】例程七:信号量——任务同步

    实验指导书及代码包下载: http://pan.baidu.com/s/1kVjeN2n iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...