获取文件系统中ASP.NET MVC站点的路径 [英] Get path of ASP.NET MVC site in the file system

查看:244
本文介绍了获取文件系统中ASP.NET MVC站点的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET MVC项目,该项目具有一个名为emails的子文件夹.其中包含我的电子邮件模板的HTM文件.在网站的某些位置,我有一个控制器,需要加载这些模板之一并将其作为电子邮件发送.

I've an ASP.NET MVC project that has a sub folder called emails. This contains HTM files for my email templates. At certain points in the site, I have a controller that needs to load one of these templates and send it as an email.

我想做的是使用反射来获取当前正在执行的程序集的路径,但是它没有按我期望的那样工作.我返回的路径是:

What I'm trying to do is use reflection to get the path of the current executing assembly but it's not working as I would expect it. The path I am getting back is:

var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

'C:\ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ Temporary ASP.NET iles \ ssl \ 1da130c4 \ f8e7810e \ assembly \ dl3 \ 5f253aca \ 1a71f123_e83bcc01 \ Emails \ ProductAccountConfirmation.htm'

'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET iles\ssl\1da130c4\f8e7810e\assembly\dl3\5f253aca\1a71f123_e83bcc01\Emails\ProductAccountConfirmation.htm'

我发现这很奇怪,因为该站点是通过Visual Studio托管在IIS中的.我本来以为这会给我dll在开发人员的项目文件夹中的位置,以及生产环境中IIS的部署文件夹.

I find this strange as the site is being hosted in IIS via Visual Studio. I would have thought this would give me the dll location in my project folder in dev and the deploy folder for IIS in production.

推荐答案

您正在寻找的是

What you are looking for is Server.MapPath(), it will give you the path of the application that you are executing.

这篇关于获取文件系统中ASP.NET MVC站点的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆