0

在我的 Asp.Net MVC 应用程序中,我使用了自定义的 twitter bootstrap 模板。我已将这个名为“b3-detail-admin”的模板文件夹放在我的 mvc 应用程序的根目录上。使用浏览器的地址栏,当我尝试直接从该文件夹访问一个文件时,如下所示:

http://my-pc/MyWebAppMvc/b3-detail-admin/font/fontawesome-webfont.woff

我收到以下错误:

HTTP Error 404.3 - Not Found
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.

我应该怎么做才能直接访问“b3-detail-admin”文件夹下的所有文件/文件夹?

4

1 回答 1

-1

在 mvc 中,您只能访问 RouteConfig 中定义的路由。您可以添加一个 ActionResult 来返回文档,如下所示:

public ActionResult GetPdf()
{
     string file = Server.MapPath("~/folder/file.pdf");
     return File(file, "application/pdf", "file.pdf");
}

然后,您可以动态获取各种文件:

public ActionResult GetFile(string url, string mime)
{
     string file = Server.MapPath(url);
     string filename = url.Split(new char[]{'/'})[url.Split(new char[]{'/'}).Count()];
     return File(file, "mime", filename);
}
于 2013-11-13T09:37:34.673 回答