Under ASP.NET and IIS, if I have a virtual path in the form "~/content", I can resolve this to a physical location using the MapPath method:
HttpContext.Server.MapPath("~/content");
How can you resolve a virtual paths to a physical location under an OWIN host?
Virtual Path or Relative Virtual Path: The path that the application identifies or is identified by from its Web server. For instance, in IIS (or OWIN) you may have a resource directory for your images in folder c:\\inetpub\ftp\images but the developer maps this folder to the app like so... ~\Images .
Virtual path. This is the logical path to access the file which is pointed to from outside of the IIS application folder. Let's display this image from Hard-drive 'E:' using a virtual directory in IIS default web site.
You may use AppDomain.CurrentDomain.SetupInformation.ApplicationBase to get root of your application. With the root path, you can implement "MapPath" for Owin.
I do not know another way yet. (The ApplicationBase
property is also used by Microsoft.Owin.FileSystems.PhysicalFileSystem.)
You shouldn't use HttpContext.Server
as it's only available for MVC. HostingEnvironment.MapPath()
is the way to go. However, it's not available for self-hosting owin. So, you should get it directly.
var path = HostingEnvironment.MapPath("~/content"); if (path == null) { var uriPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase); path = new Uri(uriPath).LocalPath + "/content"; }
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