MVC4 - Is there a way to route the root to a “normal” unprocessed html page?

我是研究僧i 提交于 2019-12-21 07:56:16

问题


I have an MVC4 app, but I'm primarily using it for the WebAPI parts. I want to have a "plain old HTML" file sent back to the user (which will then use KnockoutJS or KendoUI to pull JSON from the webapi controllers).

I know I can do this:

routes.IgnoreRoute("{page}.html");

And then if I browse to "localhost/index.html" it does successfully just return my .html page. However, I really want to map the "root" default path "localhost/" to return my index.html.

I tried this:

routes.MapPageRoute("root", "", "~/index.html");

but that throws the error:

There is no build provider registered for the extension '.html'. You can register one in the <compilation><buildProviders> section in machine.config or web.config. Make sure is has a BuildProviderAppliesToAttribute attribute which includes the value 'Web' or 'All'.

Anyone have any ideas on how I can make this work? I could just hit a default controller that returns a plain html page, but it seems like overkill to go through the entire ASP.NET stack once for the HTML page, which then just calls a WebAPI URL to go back through the ASP.NET stack to get some JSON data for the page's model.

I basically just want to "skip" all the MVC plumbing and have IIS send me back the html page, as if it wasn't an ASP.NET app, or at least do as little processing as possible.


回答1:


Add the following to your routing config:

routes.IgnoreRoute("");


来源:https://stackoverflow.com/questions/12417437/mvc4-is-there-a-way-to-route-the-root-to-a-normal-unprocessed-html-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!