asp.net-mvc-3 - MVC 3到./bin/的相对路径

标签 asp.net-mvc-3 path

我正在构建一个MVC 3项目,该项目需要在 Controller 中按路径引用位于该项目的\bin\文件夹中的程序集。

有人可以指出正确的方向来构建\bin\文件夹的相对路径吗?

在VS 2010中以 Debug模式运行项目会导致当前目录为C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0,因此使用.\bin\在该路径中查找bin文件夹。

谢谢

最佳答案

您可以使用当前的appdomain来获取此信息。

// 1) get current directory for this loaded assembly
// 2) combine path to get \bin folder 
var path = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "bin");

关于asp.net-mvc-3 - MVC 3到./bin/的相对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7188757/

相关文章:

c# - MVC3 输入相关验证

c# - ASP.NET MVC 中的数据库上下文和返回动态结果集

python - open() 给出 FileNotFoundError/IOError : Errno 2 No such file or directory

c - -I/path 和 -L/path 放入代码中

asp.net-mvc - 减小 asp.net mvc Controller 的大小

.net - 如何在 Asp.net MVC3 中为初学者级别连接 SQL 数据库

.net - 在应用程序 web.config 中设置时,IIS 7.5 不压缩 JSON

image - 使用image_tag忽略主机的Rails邮件程序

javascript - 如何使用 Rapheal.js 库逐渐将路径动画化为圆形

java - 为什么 Context ClassLoader 返回带有感叹号的路径?