Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using MapPath from a worker thread

I have a WCF service method that's running in a worker thread I spin from another method.
I need to map a relative service app path ("~/Templates/a.template") to the physical path ("D:\Web\Templates\a.template"), but I can't use HttpContext.Current.Server.MapPath because HttpContext.Current is null in a worker thread. How else can I reach MapPath method?

like image 992
Andrey Avatar asked Feb 24 '10 23:02

Andrey


People also ask

How do I use MapPath?

If the path starts with either a forward slash(/) or backward slash(\) the MapPath Method returns a path as if the path is a full virtual path. If the path doesn't start with a slash, the MapPath Method returns a path relative to a directory of the . asp file being processed.

What is Server MapPath in asp net c#?

Server. MapPath specifies the relative or virtual path to map to a physical directory. Server.MapPath(".") 1 returns the current physical directory of the file (e.g. aspx) being executed.

Is a physical path but a virtual path was expected in asp net?

Generally this physical and virtual path problem occurred whenever we refer “Server. MapPath” value multiple times while using folder path in applications. To solve this e:is a physical path but a virtual path was expected we need to use Server.


2 Answers

Use System.Web.Hosting.HostingEnvironment.MapPath().

No HttpContext required and it does the same work.

like image 188
mas_oz2k1 Avatar answered Oct 13 '22 21:10

mas_oz2k1


I actually figured out a workaround - I use HostingEnvironment.ApplicationPath to get physical path of WCF service, and add the relative path to it.

like image 43
Andrey Avatar answered Oct 13 '22 20:10

Andrey