I have a class that inherits from DelegatingHandler. In one of the methods of that class I am trying to access a text files like so:
string filePath = HttpContext.Current.Server.MapPath("~/test.txt");
if (!string.IsNullOrWhiteSpace(filePath))
{
using (StreamWriter w = File.AppendText(filePath))
{
w.WriteLine(string.Format("{0}|{1})", DateTime.Now, ex.ToString()));
}
}
But I keep getting a null error on HttpContext.Current cannot be null
string filePath = HttpContext.Current.Server.MapPath("~/test.txt");
What could the issue be? I have made sure the file does exist at the site root?