ASP.NET ~ 解决
我有一个 asp.net 应用程序,它有各种文本文件,需要在启动时加载到内存缓存中。它们是电子邮件正文模板。
我将它们作为 Visual Studio 项目中的文件(使用 File.ReadAllText),但是当我尝试加载它们时,它会在开发 Web 服务器主目录而不是应用程序目录中查找。
所以我需要解决 ~ 但我还没有 HttpRequest 来执行它(因为这是在应用程序启动时)。如何在应用程序启动期间获取“~/StandardEmails/Sample.txt”的绝对路径?
I have an asp.net application that has various text files it needs to load into a memory cache at start up. They are email body templates.
I have them as files in my project in Visual studio, (with File.ReadAllText) but when I try to load them it is looking in the development web server home directory rather than the application directory.
So I need to resolve ~ but I don't yet have an HttpRequest to do it with (since this is at application start up.) How can I get the absolute path of "~/StandardEmails/Sample.txt" during application startup?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试 HttpContext.Current.Server.MapPath("~/StandardEmails/Sample.txt") 。
Try
HttpContext.Current.Server.MapPath("~/StandardEmails/Sample.txt")
.