1

我正在尝试映射任何不api/以返回静态 html 文件开头的请求。这是我已经拥有的映射:

public static class WebApiConfig {
    public static void Register(HttpConfiguration config) {
        config.MapHttpAttributeRoutes();
        config.Routes.MapHttpRoute(
            "DefaultApiWithId",
            "api/{controller}/{id}",
            null,
            new { id = @"\d.+" });
        config.Routes.MapHttpRoute(
            "DefaultApiWithAction",
            "api/{controller}/{action}");
        ...
        // controller injector
    }
}

理想情况下,我希望有类似的东西:

config.Routes.MapHttpRoute(
    "NotAPI",
    "^(?!api\/).*",
    "~/index.html"
    );

到目前为止,我只使用以下代码设法使应用程序在没有其他路由匹配时返回特定操作:

config.Routes.MapHttpRoute(
    "NotAPI",
    "{*url}",
    new { Controller = "Test", Action = "Test" } // currently just returning `Ok("Hello World")`
    );

有没有办法直接将请求映射到文件,还是我必须读取文件并返回其内容?

4

0 回答 0