背景
在默认情况下,MVC框架是支持对服务器静态资源的访问的,我们在项目根目录下新建一个Content文件夹,然后添加一个命名为“StaticContent.html”的html文件,如下图所示:
StaticContent.html中的代码如下图所示:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<meta charset="utf-8" />
</head>
<body>
This is the static html file(~/Content/StaticContent.html)
</body>
</html>
运行项目,输入URL,可以看到能访问到这个文件:
为磁盘文件定义路由
为了安全考虑,希望用户不能访问某些文件夹,我们可以增加如下代码:
public static void RegisterRoutes(RouteCollection routes)