0

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?

2
  • I think it has something to do with different threads. Commented Nov 7, 2016 at 12:39
  • Have you given the administrator priviliges to your compiler ? Commented Nov 7, 2016 at 12:52

1 Answer 1

1
string filePath = Server.MapPath("~/test.txt");
  • Use this Server.MapPath, it return the current full path of application
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.