Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Redirect the root path of an Owin hosted application to the swagger end point
using System.Net;
using Owin;
namespace MyApplication.Api.Extensions
{
// ReSharper disable once InconsistentNaming
public static class IAppBuilderExtensions
{
public static IAppBuilder RedirectRootToSwagger(this IAppBuilder app)
{
app.Use(async (ctx, next) =>
{
if (ctx.Request.Path.Value == "/")
{
ctx.Response.StatusCode = (int)HttpStatusCode.Redirect;
ctx.Response.Headers.Set("Location", ctx.Request.Uri + "swagger");
}
else
{
await next();
}
});
return app;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.