Phi*_*ens 8 c# asp.net-web-api
我正在尝试创建一个Asp.net WebApi /单页面应用程序.如果没有给出路由,我希望我的服务器分配index.html.我希望它以正常的"{controller}/{id}"方式指定一个控制器.
我意识到我可以使用http:// localhost:555/index.html访问我的索引页面.我如何通过访问http:// localhost:555来做同样的事情?
只需为您的WebApiConfig文件添加一个路径以获取索引页面.您的方法应如下所示:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Attribute routing
config.MapHttpAttributeRoutes();
// Route to index.html
config.Routes.MapHttpRoute(
name: "Index",
routeTemplate: "{id}.html",
defaults: new {id = "index"});
// Default route
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6965 次 |
| 最近记录: |