Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVC4,获取类库中的绝对路径_C#_Asp.net Mvc 4 - Fatal编程技术网

C# MVC4,获取类库中的绝对路径

C# MVC4,获取类库中的绝对路径,c#,asp.net-mvc-4,C#,Asp.net Mvc 4,我的类库中有一个类,它在将结果返回到Web之前对文件进行各种验证和一致性检查,它在WebForms中使用时效果良好: System.Web.HttpContext.Current.Server.MapPath("myFilePath here"); 但是现在我正在用MVC做同样的事情,路由正在弄乱映射路径。 如何使用MvC在类库中获取应用程序的“基本”路径 HttpContext.Server.MapPath("~/myFilePath here"); 我通常会将该路径从控制器传递到需要它的

我的类库中有一个类,它在将结果返回到Web之前对文件进行各种验证和一致性检查,它在WebForms中使用时效果良好:

System.Web.HttpContext.Current.Server.MapPath("myFilePath here");
但是现在我正在用MVC做同样的事情,路由正在弄乱映射路径。 如何使用MvC在类库中获取应用程序的“基本”路径

HttpContext.Server.MapPath("~/myFilePath here");

我通常会将该路径从控制器传递到需要它的助手库

其他选择是使用:

System.Web.Hosting.HostingEnvironment.MapPath("~/Your relative path from root website")

顺便说一句,要使用HostingEnvironment.MapPath(),您需要添加对System.Web的引用。

还有另一个线程在讨论它: