首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

如何从ASP.NET MVC中的Controller构造函数中找到文件夹的路径?

要从ASP.NET MVC中的Controller构造函数中找到文件夹路径,可以使用以下方法:

  1. 使用HttpContext.Current.Server.MapPath方法:
代码语言:csharp
复制
string folderPath = HttpContext.Current.Server.MapPath("~/your-folder-name");
  1. 使用HostingEnvironment.MapPath方法:
代码语言:csharp
复制
using System.Web.Hosting;

string folderPath = HostingEnvironment.MapPath("~/your-folder-name");
  1. 使用Path.Combine方法:
代码语言:csharp
复制
using System.IO;

string folderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "your-folder-name");

其中,"~/your-folder-name" 是相对于应用程序根目录的文件夹路径。这些方法将返回文件夹的绝对路径。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

领券