首页 > 代码库 > C# 后台获取请求来源

C# 后台获取请求来源

 

 /// <summary>
        /// 下载APP
        /// </summary>
        /// <returns></returns>
        [AllowAnonymous]
        [Route("download/app")]
        public ActionResult DownloadApp() {

            string android = "android";
            //获取客服端请求源
            string agent = Request.UserAgent;
            string[] keywords = { "Android", "iPhone", "iPod", "iPad", "Windows Phone", "MQQBrowser" };

            // CloudWave.Framework.Core.Logging.Logging4net.WriteInfo(agent);
            //排除 Windows 桌面系统           
            //if (!agent.Contains("Windows NT") || (agent.Contains("Windows NT") && agent.Contains("compatible; MSIE 9.0;")))
            var downloadurl = "";
            //判断是微信, 直接响应应用宝地址
            if (agent.ToLower().Contains("micromessenger")) {
                //获取配置信息
                var wxUrl = ConfigurationManager.AppSettings["YingYongBao"];
                if (!string.IsNullOrEmpty(wxUrl)) {
                    return Redirect(wxUrl);
                }
                return RedirectToAction("index");
            }
            if (agent.ToLower().Contains(android)) {
                downloadurl = ConfigurationManager.AppSettings["AndroidUrl"];
                if (string.IsNullOrEmpty(downloadurl)) {
                    return RedirectToAction("index");
                }
            } else {
                downloadurl = ConfigurationManager.AppSettings["IOSUrl"];
                if (string.IsNullOrEmpty(downloadurl)) {
                    return RedirectToAction("index");
                }
                if (agent.ToLower().Contains("weibo")) {
                    downloadurl = "itms-apps" + downloadurl.Substring(downloadurl.IndexOf(":")); //itms-apps://
                }
            }
            return Redirect(downloadurl);
        }

 

C# 后台获取请求来源