Skip to content

Instantly share code, notes, and snippets.

@JamesRandall
Created August 13, 2016 09:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesRandall/314ac64a1cac7ecf21be4fe34e07a68f to your computer and use it in GitHub Desktop.
Save JamesRandall/314ac64a1cac7ecf21be4fe34e07a68f to your computer and use it in GitHub Desktop.
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