问题描述
我是.Net的新手,并使用.Net核心创建简单的Web应用程序。现在,它使用Razor页面查看其静态内容。
这是项目结构,
我只能将.cshtml文件用于导航,例如
https://localhost:44391/Home //goes to Home.cshtml
https://localhost:44391/About //goes to About.cshtml
我有一个静态HTML文件,并将一些必需的资产放在 Pages 文件夹中名为“ 关闭”的子文件夹中。
https://localhost:44391/Off
我知道,我可以使用Razor页面本身。但是在这里,我下载了一些第三方集成,它提供了此功能,并要求我使用html页面在相同的层次结构中进行访问。
我可以知道吗?
解决方法
我有一个静态html文件,并且在Pages文件夹中的子文件夹“ Off”中放置了一些必需的资产。
https://localhost:44391/Off
您可以尝试致电app.UseFileServer
到enable the serving of static files。
//...
app.UseStaticFiles();
app.UseFileServer(new FileServerOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(env.ContentRootPath,"Pages/Off")),RequestPath = "/Off"
});
app.UseRouting();
//...
测试结果
,是的,有可能,您可以尝试将html页面内容包括为部分视图:
@Html.Partial("~/Pages/Off/index")
这是在您只想在MVC网站中显示html页面内容的情况下。如果第三方集成需要一些特殊的功能,那么我们将需要对该场景进行进一步的解释。