【问题标题】:Getting Project Root Path In Controller ASP.NET MVC?在控制器 ASP.NET MVC 中获取项目根路径?
【发布时间】:2011-07-09 09:42:07
【问题描述】:

我正在为我的 css 使用 dotlesscss,我记得如何使用它,但我忘记了如何获取根项目路径,以便我可以生成 .less 文件的完整文件路径以获取更少的引擎解析。如何获取项目根路径,以便为我的 less 文件生成路径?

【问题讨论】:

    标签: c# asp.net asp.net-mvc path


    【解决方案1】:
    Server.MapPath("~");
    

    或:

    HostingEnvironment.ApplicationPhysicalPath 
    

    【讨论】:

    • 更好地使用HostingEnvironment.ApplicationPhysicalPath,因为在某些情况下HttpContext.Current.Server 可以是null——例如,如果从派生的工作线程调用。
    • HostingEnvironment.ApplicationPhysicalPath 在 System.Web.Hosting 命名空间中。
    • 如果 Server.MapPath 不起作用。试试 System.Web.HttpContext.Current.Server.MapPath(saveAsLocation)
    • 有没有办法将此代码添加到 Web.Config 文件中?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-02-07
    • 1970-01-01
    • 2019-03-21
    • 1970-01-01
    • 1970-01-01
    • 2021-01-22
    • 1970-01-01
    相关资源
    最近更新 更多