我有一个webapi项目,我不想返回任何html或razor视图。我希望默认控制器和操作是我的一个API控制器的HTTP GET。我的代码如下:
MVC路由配置:
ansiText
WebApi路线配置:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
RouteTable.Routes.MapRoute(
"Default",
"{controller}/{id}",
new { controller = "Enpoint", action = "Get", id = UrlParameter.Optional }
);
}
}
的Application_Start:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "ApiDefault",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
您知道如何配置路由器默认重定向到:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
}