我正在用.NET开发一个WEB API,我想用swagger来记录它 . 我的默认路线是:

config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

但是当我尝试访问localhost时,它给了我这个错误:55800 / swagger:

{
  "$id": "1",
  "message": "No HTTP resource was found that matches the request URI 'http://localhost:55800/swagger/ui/index'.",
  "messageDetail": "No type was found that matches the controller named 'swagger'."
}

我用这个命令改变了招摇的路线:

config.EnableSwaggerUi("apihelp/{*assetPath}", c => 
    ... // following lines omitted

但我仍然无法从MapHttpRoute方法中的routeTemplate中删除“api”前缀 .

如何在MapHttpRoute上识别没有此“api”前缀的路线?