Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Swagger as default start page?

How do I set Swagger as the default start page in ABP template instead of /Account/Login?

I'm using ASP.NET MVC 5.x + Angular 1.x.

Update

Current code:

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 }     ); } 

Everything is still working fine, except Module Zero's "api/Account/Authenticate" request that has broken, showing:

The resource cannot be found.

like image 707
Cristina Pereira Cunha Avatar asked Nov 23 '17 14:11

Cristina Pereira Cunha


People also ask

What is the default swagger URL?

Add and configure Swagger middleware The generated document describing the endpoints appears as shown in OpenAPI specification (openapi. json). The Swagger UI can be found at https://localhost:<port>/swagger .

What is swagger in C#?

Swagger (OpenAPI) is a language-agnostic specification for describing REST APIs. It allows both computers and humans to understand the capabilities of a REST API without direct access to the source code.


2 Answers

For a RESTFUL API in ASP Net Core >2.2, set the default URL in Project/Properties/ Debug

Default URL In Resful API dot net core 2.2

like image 175
JimbobTheSailor Avatar answered Oct 05 '22 22:10

JimbobTheSailor


Add this routing in RouteConfig.cs as commented out here:

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 }     ); } 
like image 41
aaron Avatar answered Oct 05 '22 22:10

aaron