Redirects

The redirect provider allows to inform the client that the location of the actual resource is different than the requested URI.

C#
await Host.Create()
          .Handler(Redirect.To("http://google.com"))
          .RunAsync();

In this example, accessing http://localhost:8080 will redirect the client to the Google search engine. Redirect.To(location, temporary) accepts the target as an absolute or relative URI string and a temporary flag (false by default) as its second argument. The status code sent depends on both this flag and the request method: GET/HEAD requests receive a 301 Moved Permanently or, if temporary is set, a 307 Temporary Redirect; other methods receive a 308 Permanent Redirect, which repeats the request with the same method and body at the new location, or, if temporary is set, a 303 See Other, which tells the client to fetch the new location with GET.

C#
Redirect.To("https://genhttp.org", temporary: true);