你如何在 ASP.NET MVC 中的 ~/Views 文件夹下请求静态 .html 文件?

问题描述:

我希望能够请求位于 ~/Views 文件夹中的静态 .html 文件.根据文档,路由系统会在评估应用程序的路由之前检查 URL 是否与磁盘文件匹配.

I want to be able to request static .html files which are located in the ~/Views folder. According to the documentation, the routing system checks to see if a URL matches a disk file before evaluating the application's routes.

但是当我请求文件时,会出现 404 错误.

But when I request the file a 404 error arises.

我的文件位于 ~/Views 文件夹中.网址为:http://[localhost]/Views/HtmlPage1.html

My file is located in ~/Views folder. The URL is: http://[localhost]/Views/HtmlPage1.html

我错过了什么?

我希望能够请求位于~/Views"文件夹中的静态 .html 文件.

I want to be able to request static .html files which are located in the '~/Views' folder.

你不能.此文件夹中有一个 web.config 文件,它明确禁止从中访问任何文件.如果您希望能够从客户端访问文件,则不应将这些文件放在 Views 文件夹中,该文件夹在 ASP.NET MVC 中具有特殊含义.

You can't. There's a web.config file in this folder which explicitly forbids accessing any file from it. If you want to be able to access files from the client those files should not be placed in the Views folder which has a special meaning in ASP.NET MVC.

您可以有一个 ~/Static 文件夹,您可以在其中放置 HTML 文件.然后像这样访问它:

You could have a ~/Static folder where you could place your HTML files. And then access it like that:

http://example.com/yourapplicationname/static/foo.html