@manhnguyenv

Welcome to my blog!

How to redirect root to swagger in Asp.Net Core 2.x?

December 1, 2019 12:41

How to redirect root to swagger in Asp.Net Core 2.x? (edit)

 public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime applicationLifetime, ILoggerFactory loggerFactory)
{
app.UseStartupService(env, applicationLifetime, configuration: Configuration, loggerFactory: loggerFactory);
app.UseProductionStartupService(env, applicationLifetime, Configuration);
app.UseCustomService(Configuration);

var option = new RewriteOptions();
option.AddRedirect("^$", "swagger");
app.UseRewriter(option);

app.UseMvc();
}

https://stackoverflow.com/questions/49290683/how-to-redirect-root-to-swagger-in-asp-net-core-2-x

In Startup.cs

public void Configure(IApplicationBuilder app, IHostingEnvironment env)

before

app.UseMvc();

add

var option = new RewriteOptions();
option.AddRedirect("^$", "swagger");
app.UseRewriter(option);

Set default page (C#)

https://docs.microsoft.com/en-us/iis/configuration/system.webserver/defaultdocument/

Set default page for your website in Web.config

https://www.aspsnippets.com/Articles/Set-default-page-for-your-website-in-IIS-using-WebConfig-file-in-ASPNet.aspx

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="bin\IISSupport\VSIISExeLauncher.exe" arguments="-argFile IISExeLauncherArgs.txt" stdoutLogEnabled="false">
<environmentVariables />
</aspNetCore>
<modules runAllManagedModulesForAllRequests="false">
<remove name="WebDAVModule" />
</modules>
<directoryBrowse enabled="true" />
<defaultDocument>
<files>
<clear />
<add value="~/swagger/index.html" />
</files>
</defaultDocument>
</system.webServer>
</location>
</configuration>

How to set in Visual Studio Startup Page in web config

https://forums.asp.net/t/1934284.aspx?How+to+set+in+Visual+Studio+Startup+Page+in+web+config+

ASP.NET Core 3.0 + EF Core 3.0 + Web API + Swagger + JWT

October 7, 2019 21:29

ASP.NET Core 3.0 + EF Core 3.0 + Web API + Swagger + JWT

Dependencies

EF Core 3.0

 

 

Swaager

Authorization: Bearer eyJhb...Do

cUrl (link download)

curl -X POST "https://localhost:5001/api/v1/identity/register" -H "accept: */*" -H "Content-Type: application/json" -d "{\"email\":\"test@abc.com\",\"password\":\"Abc@123!\"}" -k

curl -X POST "https://localhost:5001/api/v1/identity/login" -H "accept: */*" -H "Content-Type: application/json" -d "{\"email\":\"test@abc.com\",\"password\":\"Abc@123!\"}" -k

curl -X POST "https://localhost:5001/api/v1/posts" -H "accept: */*" -H "Authorization: Bearer eyJhb...Do" -H "Content-Type: application/json" -d "{\"name\":\"ASP.NET Core + EF Core + WebAPI\",\"tags\":[\"ASP.NET Core\"]}" -k

Source code (link download)

Categories

Recent posts