Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

No, it is not possible to inject IWebHostEnvironment directly into a vbhtml file. The Razor view engine, which parses vbhtml files, does not support dependency injection by default. However, you can pass the IWebHostEnvironment instance as a parameter to a view through the ViewBag or ViewData objects, and then access it in the vbhtml file. For example:

In your controller:

public IActionResult Index()
{
    ViewBag.Environment = _env;
    return View();
}

In your vbhtml file:

@Code
    Dim env = TryCast(ViewBag.Environment, IWebHostEnvironment)
End Code