Cri*_*nha 7 c# angularjs asp.net-mvc-5 swagger-ui aspnetboilerplate
如何将Swagger设置为ABP模板中的默认起始页而不是/Account/Login?
我正在使用ASP.NET MVC 5.x + Angular 1.x.
当前代码:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
//ASP.NET Web API Route Config
routes.MapHttpRoute(
name: "swagger_root",
routeTemplate: "",
defaults: null,
constraints: null,
handler: new RedirectHandler((message => message.RequestUri.ToString()), "swagger"));
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
Run Code Online (Sandbox Code Playgroud)
一切都工作正常,除了模块零的"api/Account/Authenticate"请求已经破坏,显示:
无法找到该资源.
Jim*_*lor 33
对于 ASP Net Core >2.2 中的 RESTFUL API,在 Project/Properties/Debug 中设置默认 URL
JCi*_*sar 13
我知道主要问题是针对 ASP.Net MVC,但对于 ASP.Net Core,这个答案是一个很好的解决方案(使用 SwaggerUI):https ://stackoverflow.com/a/50127631/1179562
app.UseSwaggerUI(c =>
{
c.RoutePrefix = "";
...
};
Run Code Online (Sandbox Code Playgroud)
Ian*_*ink 10
在 Asp .Net Web Api Core 3.x 中只需执行以下操作(RoutePrefix):
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Baha'i Prayers API");
c.InjectStylesheet("/swagger/custom.css");
c.RoutePrefix = String.Empty;
});
Run Code Online (Sandbox Code Playgroud)
我转到“解决方案资源管理器面板”>“属性”。我在那里找到了一个名为 launchsettings.json 的文件。
\n\n在此文件中,我在找到它的所有部分中将“launchUrl”参数的值更改为“swagger/index.html”。
\n\n它\xc2\xb4s 对我有用。
\n在RouteConfig.cs中添加此路由,如下所示:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
//ASP.NET Web API Route Config
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
// Set Swagger as default start page
/*
routes.MapHttpRoute(
name: "swagger_root",
routeTemplate: "",
defaults: null,
constraints: null,
handler: new RedirectHandler((message => message.RequestUri.ToString()), "swagger"));
*/
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
Run Code Online (Sandbox Code Playgroud)
小智 5
对于.Net core 3.1,更改launchSettings.json文件中的配置
搜索 launchSettings.json 文件将属性“launchUrl”值更改为“swagger”。参考下面:
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"AfterPayAPI": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
Run Code Online (Sandbox Code Playgroud)