网页跳H5实例

        public static void CheckAgent()
        {
            string redirect = string.Empty;
            string agent = HttpContext.Current.Request.UserAgent;
            string path = HttpContext.Current.Request.Url.AbsolutePath;
            string[] keywords = { "Android", "iPhone", "iPod", "iPad", "Windows Phone", "MQQBrowser" };
            //排除 Windows 桌面系统 
            if (!agent.Contains("Windows NT") || (agent.Contains("Windows NT") && agent.Contains("compatible; MSIE 9.0;")))
            {
                //排除 苹果桌面系统 
                if (!agent.Contains("Windows NT") && !agent.Contains("Macintosh"))
                {
                    foreach (string item in keywords)
                    {
                        if (agent.Contains(item))
                        {
                            redirect = System.Configuration.ConfigurationManager.AppSettings["WebH5URL"];
                            if (string.IsNullOrEmpty(redirect))
                            {
                                redirect = new MemberManageBLL().GetPublicConfig("WebH5URL");
                            }
                            break;
                        }
                    }
                }
            }
            else
            {
                redirect = System.Configuration.ConfigurationManager.AppSettings["WebFrontURL"];//web.config里配置的url
                if (string.IsNullOrEmpty(redirect))
                {
                    redirect = new MemberManageBLL().GetPublicConfig("WebFrontURL");
                }
                if (path.ToLower().Contains("hhreg.aspx"))
                    redirect += "/Regist.aspx";
                if (path.ToLower().Contains("login.aspx"))
                    redirect += path;
            }
            Uri rUrl = new Uri(redirect);
            if ((rUrl.Host == HttpContext.Current.Request.Url.Host && rUrl.Port == HttpContext.Current.Request.Url.Port) || HttpContext.Current.Request.Url.Host.Contains("localhost"))
                return;
            HttpContext.Current.Response.Redirect(redirect);
        }

上面是H5跳网页的例子

        public static void CheckAgent()
        {
            string redirect = string.Empty;
            string agent = HttpContext.Current.Request.UserAgent;
            string[] keywords = { "Android", "iPhone", "iPod", "iPad", "Windows Phone", "MQQBrowser" };
            string path = HttpContext.Current.Request.Url.AbsolutePath;
            //排除 Windows 桌面系统 
            if (!agent.Contains("Windows NT") || (agent.Contains("Windows NT") && agent.Contains("compatible; MSIE 9.0;")))
            {
                //排除 苹果桌面系统 
                if (!agent.Contains("Windows NT") && !agent.Contains("Macintosh"))
                {
                    foreach (string item in keywords)
                    {
                        if (agent.Contains(item))
                        {
                            redirect = System.Configuration.ConfigurationManager.AppSettings["WebH5URL"];
                            if (string.IsNullOrEmpty(redirect))
                            {
                                redirect = new BLL.MemberManageBLL().GetPublicConfig("WebH5URL");
                            }
                            break;
                        }
                    }
                }
                if (path.ToLower().Contains("regist.aspx") || path.ToLower().Contains("regcode.aspx"))
                    redirect += "/HHReg.aspx";
                if (path.ToLower().Contains("login.aspx"))
                    redirect += path;
            }
            else
            {
                redirect = System.Configuration.ConfigurationManager.AppSettings["WebFrontURL"];
                if (string.IsNullOrEmpty(redirect))
                {
                    redirect = new BLL.MemberManageBLL().GetPublicConfig("WebFrontURL");
                }
            }
            Uri rUrl = new Uri(redirect);
            if ((rUrl.Host == HttpContext.Current.Request.Url.Host && rUrl.Port == HttpContext.Current.Request.Url.Port) || HttpContext.Current.Request.Url.Host.Contains("localhost"))
                return;
            HttpContext.Current.Response.Redirect(redirect);
        }

网页跳H5例子

posted @ 2019-07-19 17:52  听海漫步  阅读(521)  评论(0编辑  收藏  举报