Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
655 views
in Technique[技术] by (71.8m points)

c# - Redirect to absolute URL on timeout in ASP.NET Core 2.0 application

I'm running an ASP.NET Core 2.0 application which utilises ASP.NET Identity hosted in Azure App Service behind an Application Gateway.

I've set up a custom domain to point to the Application Gateway over SSL which then terminates the SSL and forwards the request onto my backend pool which uses the default *.azurewebsites.net domain over 80.

e.g. Request to custom.com:443 ---> Application Gateway ---> custom.azurewebsites.net:80

I've configured my ASP.NET Core 2.0 application to time the users session out after 1 hour using the following middleware:

services.ConfigureApplicationCookie(options =>
{
    options.ExpireTimeSpan = TimeSpan.FromMinutes(60);
});

When the user times out and then performs another action, they're getting redirected to the login page on the app service on custom.azurewebsites.net:80 instead of back through the Application Gateway.

Is there a way to redirect to an absolute URL on timeout instead of a relative one?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Thank you Tratcher for your help on this.

It seems the Azure Application Gateway does not add the X-Forwarded-Host header so adding the app.UseForwardedHeaders() middleware was futile. Instead, I've added a configuration value that holds the host of my current environment and overrides the 'Host' property of every request with the custom domain.

app.Use((ctx, next) =>
{
    ctx.Request.Host = new HostString(options.Value.CustomDomain);
    return next();
});

The ASP.NET Identity authentication middleware then uses this value to construct the redirect URL.

I've also written Microsoft some feedback on this issue here, as I'm sure my use case cannot be uncommon.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...