/// <summary> /// 点击下载按钮之后,跳转到相应的应用市场 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnDownload_Click(object sender, EventArgs e) { var mobileDetect = new MobileDetect(Context); if (mobileDetect.IsAndroid()) { Response.Redirect("http://s1.music.126.net/download/android/CloudMusic_official_3.6.0.143673.apk"); } if (mobileDetect.IsApple()) { Response.Redirect("https://itunes.apple.com/app/id590338362"); } if (mobileDetect.IsWindowsMobile()) { Response.Redirect("https://www.microsoft.com/store/apps/9nblggh6g0jf"); } }
void context_BeginRequest(object sender, EventArgs e) { //如果请求中的Cookie包含NoThanks键或者上一次请求来自下载插入页或者当前请求就是下载插入页,那么直接返回 if (ExistNoThanksCookie() || ComingFromMobileInterstitial() || OnMobileInterstitial()) { return; } var context = HttpContext.Current; //使用当前上下文对象创建一个MobileDetect对象 var mobileDetect = new MobileDetect(context); if (mobileDetect.IsMobile()) { //如果用户拒绝下载APP,那么我们需要将他跳转回之前访问的页面 var url = context.Request.RawUrl; var encodeUrl = HttpUtility.UrlEncode(url); //重定向到下载插入页,并带上returnUrl,以防用户需要返回到之前的页面 context.Response.Redirect("MobileInterstitial.aspx?returnUrl=" + encodeUrl); } }