asp.net app download ashx

来源:互联网 发布:网络维护合同范本 编辑:程序博客网 时间:2024/06/06 11:47

z


<%@ WebHandler Language="C#" Class="AppFile" %>using System;using System.Web;public class AppFile : IHttpHandler{    const string APK = "application/vnd.android.package-archive";    const string IPA = "application/octet-stream";    public void ProcessRequest(HttpContext context)    {        string filename = HttpUtility.UrlEncode(context.Request.QueryString["name"].Trim(), System.Text.Encoding.UTF8);        string filepath = "your file path";        context.Response.ContentType = filename.EndsWith(".apk", StringComparison.OrdinalIgnoreCase) ? APK : IPA;        context.Response.AddHeader("Content-Disposition", "attachment;filename=" + filename);        context.Response.WriteFile(filepath);        context.Response.Flush();        context.Response.End();    }    public bool IsReusable    {        get        {            return false;        }    }}


0 0
原创粉丝点击