asp.net app download ashx

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;
        }
    }
}


你可能感兴趣的:(Asp.Net)