简体   繁体   中英

How to access files within the wwwroot folder of a different project?

I have 2 projects that are needing to talk to one another. The first is a ASP.NET MVC project, that when in production, has a feature where the user can edit an html template that is stored in the wwwroot folder of the project.

The second project is a C# console app that grabs some user data from a database, and then uses that data to email surveys to users. The html template from the first project is needing to be grabbed by this console app so that it can be used in sending out these emails. I was hoping to use HtmlAgilityPack to grab the html email template from the first project when it is live, something along the lines of this:

var web = new HtmlWeb();
var document = web.Load("www.sitename.com/EmailTemplate");
string text = document.ParsedText;

But I'm open to other ideas that might work in this case. More or less I think I just need to figure out how to access static html files from within the wwwroot folder from a browser path, if that's possible. Oh and these two projects are going to be running on different servers, so local paths won't work. Thank you!

在很大程度上要感谢 ADyson 的评论,在这种情况下最有意义的操作过程是在 MVC 应用程序中创建一个小 API,它获取 html 文件,控制台应用程序将调用此 API 来检索所需的 html。

I had a similar problem, and I did it by adding ~/ in the beginning of my static file addresses in my _Layout.cshtml. My template files and photos were no longer loaded in the project but the layout was loaded. This way the files were also loaded

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM