我试图获取网站根目录中文件夹的路径,并在调用控制器构造函数时将其保存到类属性中:
public TestController:Controller{
string temp;
public TestController(){
temp = "";
}
}
我已经尝试过以下方法:
temp = Server.MapPath("~/TheFolder/"); // Server is null - error.
temp = Request.PhysicalApplicationPath + @"TheFolder\"; // Request is null - error.
有任何想法吗?
AppDomain.CurrentDomain.BaseDirectory 将为您提供站点的根目录。所以:
temp = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TheFolder");
(更新感谢 Marc Gravell 的评论)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)