TackleMcClean 🏅
07/04/2024, 7:53 AMMario Lopez
07/04/2024, 8:37 AMTackleMcClean 🏅
07/04/2024, 8:44 AMprojectname.azurewebsites.net
to yourcustomdomain.com
Sure, we can hope that nobody visits the auto-assigned url's, but there's the risk of it leaking somehow and then Google might try indexing it and so on.TackleMcClean 🏅
07/04/2024, 9:10 AMMario Lopez
07/04/2024, 11:13 AMMario Lopez
07/04/2024, 11:15 AMpublic class RedirectionMiddleware
{
private readonly RequestDelegate _next;
public RedirectionMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task InvokeAsync(HttpContext httpContext)
{
// Redirect to login if user is not authenticated. This instruction is neccessary for JS async calls, otherwise everycall will return unauthorized without explaining why
if (httpContext.Request.Host.Value == "domain.azurewebsites.com")
{
httpContext.Response.Redirect("https://yourdomain.com");
}
// Move forward into the pipeline
await _next(httpContext);
}
}
public static class RedirectionMiddlewareExtensions
{
public static IApplicationBuilder UseRedirectionMiddleware(this IApplicationBuilder builder)
{
return builder.UseMiddleware<RedirectionMiddleware>();
}
}
Mario Lopez
07/04/2024, 11:17 AMProgram.cs
before Umbraco is called.
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
builder.CreateUmbracoBuilder()
.AddBackOffice()
.AddWebsite()
.AddDeliveryApi()
.AddComposers()
.Build();
WebApplication app = builder.Build();
await app.BootUmbracoAsync();
app.UseHttpsRedirection();
app.UseRedirectionMiddleware(); // <-- use it here
app.UseUmbraco()
.WithMiddleware(u =>
{
u.UseBackOffice();
u.UseWebsite();
})
.WithEndpoints(u =>
{
u.UseBackOfficeEndpoints();
u.UseWebsiteEndpoints();
});
await app.RunAsync();
D_Inventor
07/04/2024, 1:38 PMD_Inventor
07/04/2024, 1:38 PMD_Inventor
07/04/2024, 1:40 PMTackleMcClean 🏅
07/04/2024, 2:07 PMAllowedHosts
to the host we want to run on, then all other domains will only render a bad request response when reaching the server.Dean Leigh
07/05/2024, 8:11 AMChad
07/05/2024, 1:12 PMChad
07/05/2024, 1:12 PMChad
07/05/2024, 1:12 PMapp.UseRewriter(new RewriteOptions().AddRedirect("foo.azurewebsites.net(.*)$", "https://mydomain.com/$1", (int)HttpStatusCode.PermanentRedirect));