2016-12-22 91 views
2

我有一个简单的ASP MVC项目。 在这个站点下,我需要显示纯净的.html文件,而不会将路线视为控制器/操作ASP MVC允许静态HTML文件

我有文件夹文档与文件index.html在里面。 我需要下www.mydomain.com/documentation这个访问,则返回403 目前它只能在www.mydomain.com/documentation/index.html

我已经加入

routes.Ignore("developers/"); 

RouteConfig.cs

Startup.cs为OwinAppBuilder

 app.UseStaticFiles(); 

我该怎么办才能使用www.mydomain.com/documentation/index.html

+0

你能够提供其他静态文件,如.js和.png吗?你运行的是哪个版本的IIS? – Sam07

+0

也不是Core?对于核心看到:http://stackoverflow.com/a/41093539/240564 – Alexan

+0

以及我可以实际显示该文件,问题是,我需要明确写入“index.html”到URL ...当我禁用所有的MVC ,并有网站运行,一切正常 – Maarty

回答

1

在你的路线设定中新增

routes.RouteExistingFiles = true; 
routes.MapRoute(
    name: "staticFileRoute", 
    url: "Public/{*file}", 
    defaults: new { controller = "Home", action = "HandleStatic" } 
); 

在web.config中你下<system.webServer>/<handlers>从添加网站this采取

<add name="MyCustomUrlHandler2" path="Public/*" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> 

,如果你想了解更多关于它。

编辑:请注意,MapRoute中的网址在url中的目录中有Public,并且在web.config行中的网址为path。如果您的html文件不在名为Public的目录中,则需要更改该部分以匹配您的目录结构。

+0

以及这样处理路由像domain.com/documentation/index.html ..但我需要相反,我需要将像domain.com/documentation的URL转换为domain.com/documentation/index .html,显示html文件 – Maarty

+0

看看这个:[http://stackoverflow.com/a/4552992/6442320](http://stackoverflow.com/a/4552992/6442320) – Sam07