asp.net-mvc - 如何在没有控制器和视图的 asp.net mvc 中打开静态 html 文件
问题描述
我有一些 HTML 文件存储在一个文件夹中,我想打开这些 HTML 文件。
我在文件中添加了以下代码route.config
:
routes.IgnoreRoute("{file}.html");
routes.MapRoute(
name: "Default",
url: "{about.html}",
defaults: new { controller = "About", action = "Index", id =
UrlParameter.Optional });
现在这个 about.html url 已经创建,并且关于我称之为视图的控制器索引操作。所以它正在工作,但我直接从文件夹打开文件然后它没有打开。
我正面临错误
HTTP 错误 500.0 - 内部服务器错误
内部服务器错误
最可能的原因是:
IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred.
IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly.
IIS was not able to process configuration for the Web site or application.
The authenticated user does not have permission to use this DLL.
The request is mapped to a managed handler but the .NET Extensibility Feature is not installed.
我希望路径为example.com/Folder/test.html。
解决方案
我有我创建的动态页面路线如下
routes.MapRoute(
name: "Article",
url: "article/{name}.html",
defaults: new { controller = "Article", action = "Index", id = UrlParameter.Optional }
);
当我为 .html 扩展添加上述路由时,上述路由不起作用,因此我更改了 web.config 中的配置。之后它开始工作。但是当我调用静态 html 文件时,它向我显示错误。
所以为此我在我的控制器中创建了下面的代码,最后我收到了一个解决方案
public ActionResult Index(string page)
{
var pageRoute = "~/uploads/" + page + ".html";
var staticPageToRender = new FilePathResult(pageRoute, "text/html");
return staticPageToRender;
}
推荐阅读
- angular - Angular:如何在响应中获取内部对象数据?
- google-cloud-platform - 谷歌云功能部署错误与terraform
- r - 更改 geom_raster() 中列的顺序
- node.js - npm 没有正确启动,找不到模块'worker_threads
- google-cloud-dataflow - 新 Cloud Pub/Sub 订阅中的未确认消息
- reactjs - 在反应中将卡片的内容从一页传递到另一页
- javascript - JavaScript/Express Promise.all() 问题
- here-api - 逐向导航中的测量单位
- flutter - 如何为大型项目编写 injection_container(服务注入器)
- python - tesseract-ocr个位数识别如何提高?