Sandy
Sandy

Reputation: 2449

How to write the response to a file in HTTP Handler

I have HTTP Handler where I want to log the response. I know there is option context.Request.SaveAs(filename... But I never tried this before. How can I use this, I mean someone can be more specific about file name?

Upvotes: 0

Views: 960

Answers (1)

dsfgsho
dsfgsho

Reputation: 2769

Well, the documentation is pretty straight forward about this:

The [SaveAs] call specifies that the request be saved as a text file in a directory where the ASP.NET process identity has been granted write permissions, and that any header information included in the request is included in the file.

You can thus simply save the entire HttpRequest (including the headers in a file). You can simply determine the path and a boolean indicating whether you want to incude the headers as well:

context.Request.SaveAs(@"c://myLogFile.log",true)

Upvotes: 1

Related Questions