Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverse proxy and load balancer NOT supported #725

Open
xiaoliyu opened this issue Feb 15, 2022 · 0 comments
Open

Reverse proxy and load balancer NOT supported #725

xiaoliyu opened this issue Feb 15, 2022 · 0 comments

Comments

@xiaoliyu
Copy link

Environment

Windows, URLRewrite, IIS

Issues

After checked the source code, The following files should be changed. I have verified the changes and it worked well in my environment.
AddBaGetWebApplication method in IServiceCollectionExtensions.cs
` public static IServiceCollection AddBaGetWebApplication(
this IServiceCollection services,
Action configureAction)
{
services
.AddRouting(options => options.LowercaseUrls = true)
.AddControllers()
.AddApplicationPart(typeof(PackageContentController).Assembly)
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
.AddJsonOptions(options =>
{
options.JsonSerializerOptions.IgnoreNullValues = true;
});
// Enable reverse proxy and load balancer support
services.Configure(options =>
{
options.ForwardedHeaders = ForwardedHeaders.All;
});

        services.AddRazorPages();

        services.AddHttpContextAccessor();
        services.AddTransient<IUrlGenerator, BaGetUrlGenerator>();

        services.AddBaGetApplication(configureAction);

        return services;
    }`

AbsoluteUrl method in BaGetUrlGenerator.cs

` private string AbsoluteUrl(string relativePath)
{
var request = _httpContextAccessor.HttpContext.Request;

        string forwardedHost = request.Headers["HTTP_X-Forwarded-Host"];
        var proto = request.Headers["HTTP_X-Forwarded-Proto"].FirstOrDefault()??"https";
        if(!string.IsNullOrEmpty(forwardedHost))
        {
            return proto+"://"+forwardedHost + request.PathBase.ToUriComponent() + "/" + relativePath;
        }

        return string.Concat(
            request.Scheme,
            "://",
            request.Host.ToUriComponent(),
            request.PathBase.ToUriComponent(),
            "/",
            relativePath);
    }`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant