如何映射到物理路径的虚拟路径? [英] How to map virtual path to physical path?

查看:677
本文介绍了如何映射到物理路径的虚拟路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以通过HostingEnvironment(Microsoft.AspNet.Hosting命名空间)得到的WebRoot。

I know I can get WebRoot by HostingEnvironment (Microsoft.AspNet.Hosting namespace).

我需要根据我的web应用程序中在IIS中创建一个虚拟路径得到的物理路径。在IIS中,在网站根目录指向我的出版网站的wwwroot文件,有一个虚拟目录在IIS中,它指向的文件夹我的wwwroot以外的补充。我希望我能得到的虚拟目录的物理路径。在MVC 5或更早的版本,我可以使用HostingEnvironment.MapPath(System.Web命名),或者使用Server.Mappath,我应该怎么在MVC 6办?

I need to get a physical path according to a virtual path created in IIS within my web application. In IIS, the website root points to wwwroot of my published site and there is a virtual directory added in IIS which points to a folder outside of my wwwroot. I hope I can get the physical path of that virtual directory. In MVC 5 or earlier version, I can use HostingEnvironment.MapPath (System.Web namespace) or Server.MapPath, what should I do in MVC 6?

编辑:

这不是虚拟路径,但在IIS中添加虚拟目录。我希望我可以得到的虚拟目录的物理路径。我认为,虚拟目录是IIS的特定功能,它看起来像一个完整的虚拟路径的子路径,但可以是物理Web根目录以外的文件夹中。

It's not the virtual path but the virtual directory added in IIS. I hope I can get the physical path of that virtual directory. I think virtual directory is a particular feature of IIS, which looks like a sub path of a full virtual path but can be a folder outside of physical web root folder.

< STRONG> 2015年10月4日

参照的这个问题在ASP.NET主机5 回购,到目前为止,它似乎并没有我们可以得到在IIS虚拟目录的物理路径。

Refer to this issue in ASP.NET 5 Hosting repo, So far, it doesn't seem we can get the physical path of a virtual directory in IIS.

推荐答案

您可以使用 IApplicationEnvironment 为,其中包含属性 ApplicationBasePath

You can use IApplicationEnvironment for that, which contains the property ApplicationBasePath

    private readonly IApplicationEnvironment _appEnvironment;

    public HomeController(IApplicationEnvironment appEnvironment)
    {
        _appEnvironment = appEnvironment;
    }

    public IActionResult Index()
    {
        var rootPath = _appEnvironment.ApplicationBasePath;
        return View();
    }

这篇关于如何映射到物理路径的虚拟路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆