An ASHX handler allows you a discrete http handler without the overhead of processing a page request (an ASPX file).
<%@ WebHandler Language="C#" Class="Handler" %>Now, You have to create button in your .aspx page write the code as following
using System;
using System.Web;
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
var fileName = "must.sql";
var r = context.Response;
r.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
r.ContentType = "text/plain";
r.WriteFile(context.Server.MapPath(fileName));
}
public bool IsReusable {
get {
return false;
}
}
}
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("Handler.ashx");
}
No comments:
Post a Comment