Hey,
I've never used HTTP Handlers before, and I've got one working, but I'm not sure if I'm actually using it properly. I have generated a string which will be saved as a CSV file. When the user clicks a button, I want the download dialog
box to open so that the user can save the file. What I have works, but I keep reading about modifying the web.config
file and I haven't had to do that.
My Handler:
private string _data;
private string _title = "temp";
public void AddData(string data)
{
_data = data;
}
public bool IsReusable
{
get { return false; }
}
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/csv";
context.Response.AddHeader("content-disposition","filename=" + _title + ".csv");
context.Response.Write(_data);
context.Response.Flush();
context.Response.Close();
}
And this is from the page that allows the user to download: (on button click)
string dataToConvert = "MYCSVDATA....";
csvHandler handler = new csvHandler();
handler.AddData(dataToConvert);
handler.ProcessRequest(this.Context);
This works fine, but no examples I've seen ever instantiate the handler and always seem to modify the web.config. Am I doing something wrong?
Thanks