且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从助手内部获取asp.net核心中的server.MapPath

更新时间:2023-02-16 16:30:45

您需要注入IHostingEnvironment.然后:

var path = env.ContentRootPath + "Views\\" + s;

在html助手中,您可以执行以下操作:

in an html helper you can do this:

((IHostingEnvironment)html.ViewContext.HttpContext.RequestServices.GetService(typeof(IHostingEnvironment))).ContentRootPath;