We have on promise application hosted in Azure website that use on-premise custom domain. It works most of the time with the custom domain, but when session expires, it redirect to Azure website.
Since the application is dockerized and hosted on Linux web app, the web.config
rewrite rules do not work for me.
I tried using a .NET Core middleware, but the regex handle only relative path, so could not check if base url contain azurewebsite
and thus I can not redirect in this case.
var rewrite = new RewriteOptions()
.AddRedirect("the regex here check only relative path !!", "custom.domain");
app.UseRewriter(rewrite);
I tried this one also on startup throw "too many redirect" error
app.Use(async (context, next) =>
{
var url = context.Request.Host.Value;
if (url.Contains("azurewebsites"))
{
context.Response.Redirect(";);
return;
}
await next();
});
Any help on this topic would be much appreciated.
Thank you.
We have on promise application hosted in Azure website that use on-premise custom domain. It works most of the time with the custom domain, but when session expires, it redirect to Azure website.
Since the application is dockerized and hosted on Linux web app, the web.config
rewrite rules do not work for me.
I tried using a .NET Core middleware, but the regex handle only relative path, so could not check if base url contain azurewebsite
and thus I can not redirect in this case.
var rewrite = new RewriteOptions()
.AddRedirect("the regex here check only relative path !!", "custom.domain");
app.UseRewriter(rewrite);
I tried this one also on startup throw "too many redirect" error
app.Use(async (context, next) =>
{
var url = context.Request.Host.Value;
if (url.Contains("azurewebsites"))
{
context.Response.Redirect("https://custom.domain");
return;
}
await next();
});
Any help on this topic would be much appreciated.
Thank you.
Share edited Mar 7 at 12:24 marc_s 756k184 gold badges1.4k silver badges1.5k bronze badges asked Mar 7 at 11:27 moyomehmoyomeh 1073 silver badges16 bronze badges 3 |1 Answer
Reset to default 1 +50Application gateway inserts six additional headers to all requests before it forwards the requests to the backend. These headers are x-forwarded-for, x-forwarded-port, x-forwarded-proto, x-original-host, x-original-url, and x-appgw-trace-id. X-original-host header contains the original host header with which the request arrived. This header is useful in Azure website integration, where the incoming host header is modified before traffic is routed to the backend. If session affinity is enabled as an option, then it adds a gateway-managed affinity cookie. For more info, please see this link: https://learn.microsoft/en-us/azure/application-gateway/how-application-gateway-works#modifications-to-the-request
The above is according to the Microsoft's Azure Application Gateway webpage. You can capture the X-Original-Host header and redirect to it in your Startup.cs; something like this:
app.Use(async (context, next) =>
{
if (context.Request.Headers.GetValues("X-Original-Host") != null)
{
var originalHost = context.Request.Headers.GetValues("X-Original-Host").FirstOrDefault();
context.Request.Headers.Set("Host", originalHost);
}
await next.Invoke();
});
xxx.azurewebsites
and you have a domain namecustomdomain
? – pumpkin Commented Mar 11 at 14:33AAAA
orA
entries in yourDNS
table, I guess that should solve it if that is the case – pumpkin Commented Mar 11 at 14:35