I want to download any type of file on button click,so have created a .ashx page and redirected the .aspx page to the .ashx page.Is this way correct to do the task.Below mentioned code works fine.
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
var fileName = "Tracing.pdf";
var r = context.Response;
r.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
r.ContentType = "application/pdf";
r.WriteFile(context.Server.MapPath(fileName));
}
public bool IsReusable {
get {
return false;
}
}
}