你如何在 ASP.NET MVC 中的 ~/Views 文件夹下请求静态 .html 文件? [英] How do you request static .html files under the ~/Views folder in ASP.NET MVC?

查看:30
本文介绍了你如何在 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

这篇关于你如何在 ASP.NET MVC 中的 ~/Views 文件夹下请求静态 .html 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆