【发布时间】:2015-03-17 00:28:12
【问题描述】:
我正在开发一个非常简单的 SPA 风格的应用程序,我不想使用 razor,所以我只需要它来提供 HTML 文件(来自 wwwroot 文件夹),除非 js 调用我的 API 控制器。在 Web API 2 中,您可以让路由器忽略 HTML 文件,以便直接提供它们,例如
config.Routes.IgnoreRoute("Html", "{whatever}.html/{*pathInfo}");
类似于此示例:http://www.strathweb.com/2014/04/ignoring-routes-asp-net-web-api/ 是 IgnoreRoute 功能只是未实现还是已更改?
目前如果我有 app.UseMvc();在我的 Startup.cs 中,对“/”的任何获取请求都会给我这个异常:
An unhandled exception occurred while processing the request.
InvalidOperationException: The view 'Index' was not found. The following locations were searched:
/Views/Home/Index.cshtml
/Views/Shared/Index.cshtml.
Microsoft.AspNet.Mvc.Rendering.ViewEngineResult.EnsureSuccessful()
但是当我在没有 MVC 的情况下保留它时,它会在您请求“/”时提供 index.html 文件 - 显然我的 API 控制器将无法工作。
【问题讨论】:
-
我不明白你的意思是当注释掉 app.UseMvc() 时它工作正常,但是 web api 当然不能工作?你能在这里给出一些示例代码吗?
-
在我的 wwwroot 文件夹中,我有一个 index.html 文件,如果我禁用 MVC 任何对/提供 html 文件的请求,如果我在我的应用程序中启用 MVC 请求/导致此异常:InvalidOperationException :未找到视图“索引”。搜索了以下位置:/Views/Home/Index.cshtml /Views/Shared/Index.cshtml。
-
所以你希望 Index.html 即使在 MVC 为 enable.right 时也能提供服务?根据我的想法,这与您的问题无关,因为如果您在 IIS 中托管站点并将 index.html 作为默认页面,那么它将提供服务。
-
刚刚更新了问题,在 IIS express 和 VS2015 CTP5 中仍然显示相同的错误。
-
检查我的答案。希望它能解决您的问题。
标签: asp.net-core asp.net-core-mvc