c# - 指定服务器端代码的相对路径

标签 c# asp.net asp.net-mvc asp.net-mvc-4

在 HTML 中,我知道我可以指定相对路径,例如:

<a href="~/temp/Somecontent.xxx" />

我也想为我的服务器端代码设置相对路径。例如:

File.Exists("../myBusinessLibrary/Bin/Debug/myBusinessLibrary.dll");//where this is a library that supports the web project

找不到文件。我看了Environment.CurrentDirectory并得到:

"C:\\Program Files (x86)\\IIS Express"

我不认为我的程序集被复制到这个位置。有没有办法设置与服务器端代码一起使用的相对路径?

最佳答案

你可以使用下面的代码

HttpContext.Current.Server.MapPath("relativepath goes here")

关于c# - 指定服务器端代码的相对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15710984/

相关文章:

c# - ASP.NET 核心身份种子只创建最后一个用户

c# - 计时器控制间隔

asp.net - 将配置设置从 web.config 移至 ServiceConfiguration.cscfg

c# - 当 cshtml 文件丢失时,VS2017 构建不会失败; VSTS 确实失败

c# - Xmlserializer 不序列化基类成员

c# - Autofac 通用接口(interface)工厂

c# - 切换选项卡后日期选择器不起作用

asp.net - 在asp.net 中的server.transfer?

asp.net-mvc - 将 xml 发送到 ASP.NET MVC 操作方法参数

c# - 带枚举的 MVC3 RadioButtonFor