I have this ASP.NET Core MVC project:

I want to open the HTML element (html page) named Impresorashtml.html from Index.cshtml using
<a href="/Impresorashtml.html" target="_blank"> Impresoras </a>
The page opens, but I get an error:
This localhost page can't be found

It is a Razor Pages Project. Any way, no matter Razor Pages or MVC project, the static file should be located in the wwwroot folder by default. Then you could easily access it.
If you place the Impresorashtml.html in the root of the wwwroot folder. You can access it by using code below:
<a href="/Impresorashtml.html" target="_blank"> Impresoras </a>

If you place the Impresorashtml.html in the sub folder of the wwwroot folder. You can access it by using code like below:
<a href="/html/Impresorashtml.html" target="_blank"> Impresoras </a>

If you want to serve files outside of wwwroot like what you did(place it in the Pages folder), you need configure the static file middleware as follows:
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(Path.Combine(builder.Environment.ContentRootPath, "Pages")),
RequestPath = "/StaticFiles"
});
Then access it by using the code below:
<a href="/StaticFiles/Impresorashtml.html" target="_blank"> Impresorashtml</a>
Reference:
Serve files outside of web root
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With