开发者

ASP.NET ~ Resolving

开发者 https://www.devze.com 2023-03-23 16:56 出处:网络
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 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 t开发者_JAVA技巧he 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?


Try HttpContext.Current.Server.MapPath("~/StandardEmails/Sample.txt").


HttpContext.Current.Request.MapPath("~/StandardEmails/Sample.txt");
0

精彩评论

暂无评论...
验证码 换一张
取 消