asp.net 下载 apk文件 解决下载后apk文件解析包错误的问题

前端html

<!DOCTYPE html>
<html lang="zh_CN">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="description" content="">
	<meta name="keywords" content="">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
	<meta name="renderer" content="webkit">
    <style type="text/css">
	 *{margin:0; padding:0;}
	 a{text-decoration: none;}
	 img{max-width: 100%; height: auto;}
	 
    .download{color: #4D4D4D; padding: 7.2% 6.8% 9.3%;}
	.download .entry-hd{font-size: 2.4em; font-weight: bold; text-align: center;}
	.download-btn{padding-top: 9%; text-align: center;}
	.download-btn .android-btn{ width:auto; margin:0 auto;}
	
	.footer-bg{background: #2D2D2D; color: #E4E4E4; padding: 3.4% 2%; text-align: center;}
	.footer-bg .entry-con{font-size: 1em;}
	
	#weixin-tip{display:none; position: fixed; left:0; top:0; background: rgba(0,0,0,0.8); filter:alpha(opacity=80); width: 100%; height:100%; z-index: 100;} 
	#weixin-tip p{text-align: center; margin-top: 10%; padding:0 5%; position: relative;}
	#weixin-tip .close{
		color: #fff;
		padding: 5px;
		font: bold 20px/20px simsun;
		text-shadow: 0 1px 0 #ddd;
		position: absolute;
		top: 0; left: 5%;
	}
    </style>
	<title>XXXX安卓版app下载</title>
</head>
<body class="success">
	<div class="page-wrap" style="background-color:#4D4D4D">
		<div class="download">
			<h3 class="entry-hd">
            </h3>
			<div class="download-btn"><a href="http://192.168.0.109:8083/Modules/WebForm1.aspx" class="android-btn" id="J_weixin"><img src="../static/20201216150438676.png" alt="安卓版下载"></a></div>
		</div>
		<div class="footer-bg">
			<p class="entry-con">注:微信用户请在右上角选择“在浏览器中打开”,再选择下载应用</p>
		</div>
	</div>
	<div id="weixin-tip"><p><img src="img/live_weixin.png" alt="微信打开"/><span id="close" title="关闭" class="close">×</span></p></div>
	<script type="text/javascript">
	var is_weixin = (function() {
	    var ua = navigator.userAgent.toLowerCase();
	    if (ua.match(/MicroMessenger/i) == "micromessenger") {
	        return true;
	    } else {
	        return false;
	    }
	})();
	window.onload = function(){
		var winHeight = typeof window.innerHeight != 'undefined' ? window.innerHeight : document.documentElement.clientHeight;
		var btn = document.getElementById('J_weixin');
		var tip = document.getElementById('weixin-tip');
		var close = document.getElementById('close');
		if(is_weixin){
			btn.onclick = function(e){
				tip.style.height = winHeight + 'px';
				tip.style.display = 'block';
				return false;
			}
			close.onclick = function(){
				tip.style.display = 'none';
			}
		}
	}
	</script>
</body>
</html>

前端图片

 后端代码

protected void Page_Load(object sender, EventArgs e)
        {
            string userAgent = Request.UserAgent;
            if (userAgent.ToLower().Contains("micromessenger"))
            {
                //Response.Write("欢迎您在微信中访问本页。");

            }
            else
            {
                string fileName = "XXXX.apk";//客户端保存的文件名
                string filePath = Server.MapPath("~" + "/static/XXXX.apk");//路径
                FileInfo fileInfo = new FileInfo(filePath);
                Response.Clear();
                Response.ClearContent();
                Response.ClearHeaders();
                Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
                Response.AddHeader("Content-Length", fileInfo.Length.ToString());
                Response.AddHeader("Content-Transfer-Encoding", "binary");
                Response.ContentType = "application/octet-stream";
                Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
                Response.WriteFile(fileInfo.FullName);
                Response.Flush();
                Response.End();
            }


        }

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值