有一个像这样的辅助方法:
public static IHtmlContent Source(this IHtmlHelper html, string s)
{
var path = ServerMapPath() + "Views\\" + s;
我需要在 asp.net core 中获得相当于 Server.MapPath 的内容
你需要注射IHostingEnvironment
. Then:
var path = env.ContentRootPath + "Views\\" + s;
在 html 帮助器中你可以这样做:
((IHostingEnvironment)html.ViewContext.HttpContext.RequestServices.GetService(typeof(IHostingEnvironment))).ContentRootPath;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)