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?
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.
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.
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.
Use System.Web.Hosting.HostingEnvironment.MapPath().
No HttpContext
required and it does the same work.
I actually figured out a workaround - I use HostingEnvironment.ApplicationPath to get physical path of WCF service, and add the relative path to it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With