你也可以简单地使用([Route("")]
):
public class TestController : ApiController { [Route(""), HttpGet] public string Index() { return "Service is running normally..."; } }
您可以在WebApiConfig.cs中为默认URL添加路由.以下是根URL映射到方法的示例HomeController.Index()
:
config.Routes.MapHttpRoute( name: "Root", routeTemplate: "", // indicates the root URL defaults: new { controller = "Home", action = "Index" } // the controller action to handle this URL );