HttpContext.Current.Server null

I have a windows service that uses a method from a class library with the same asp.net solution. in the class library I have a method with the following line:

 reader = XmlReader.Create(HttpContext.Current.Server
             .MapPath("~/TestDevice/Data.xml"), settings);

When control passes to this line. I get an exception. I tried to debug the code and found that when the service tries to access this method, then HttpContext.Current.Serverthere is null. What is an alternative syntax.

I tried to access this class library method from a web application and it works fine.

Please suggest a solution.

+5
source share
3 answers

HttpContext.Current null, Windows IIS - -.

, :

System.Reflection.Assembly.GetExecutingAssembly().Location

^ .

+5

, Windows, -, HttpContext - . System.IO.File , , .

Edit

private String yourFullPath = System.IO.Path.GetFullPath("/YourDirectory") + @"\";
0

:

string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
0
source

All Articles