@manhng

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+

Categories