Deprecated: Assigning the return value of new by reference is deprecated in /home/gathadam/public_html/wp-settings.php on line 520

Deprecated: Assigning the return value of new by reference is deprecated in /home/gathadam/public_html/wp-settings.php on line 535

Deprecated: Assigning the return value of new by reference is deprecated in /home/gathadam/public_html/wp-settings.php on line 542

Deprecated: Assigning the return value of new by reference is deprecated in /home/gathadam/public_html/wp-settings.php on line 578

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/gathadam/public_html/wp-settings.php on line 18
2008 October

How to access HttpServerUtility.MapPath in a Thread

Usually, when you want the root directory of your website, it is easy to call:

HttpContext.Current.Server.MapPath

or just

Server.MapPath

from a page.

But if you are running your code in a thread or timer, then HttpContext.Current is null (giving you a NullReferenceException), and you are out of luck. :(

However, as long as you are not using virtual directories, there is an easy fix:

AppDomain.CurrentDomain.BaseDirectory

will give you the same result, and doesn’t depend on a current HTTP context.

This post brought to you by WeGotDomain.com - Over 10,000 Aged domains for sale!

Related posts:

  1. We Got Domain - over 10,000 aged domains for sale
  2. See how your website looks in over 60 browsers - in minutes