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

RemoteIpAddress always "127.0.0.1" #6486

Closed
Hao80617 opened this issue Dec 26, 2022 · 1 comment
Closed

RemoteIpAddress always "127.0.0.1" #6486

Hao80617 opened this issue Dec 26, 2022 · 1 comment

Comments

@Hao80617
Copy link

Hao80617 commented Dec 26, 2022

nopCommerce version:
the latest

Steps to reproduce the problem:
I added below codes to get the RemoteIpAddress.
httpContext.Connection.RemoteIpAddress?.MapToIPv4().ToString();

but,the RemoteIpAddress was always 127.0.0.1.

I followed the advice from :
aspnet/IISIntegration#140
https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-7.0

I modified code as below :

public static void UseNopProxy(this IApplicationBuilder application)
        {
            var appSettings = EngineContext.Current.Resolve<AppSettings>();

            if (appSettings.Get<HostingConfig>().UseProxy)
            {
                var options = new ForwardedHeadersOptions
                {
                    //ForwardedHeaders = ForwardedHeaders.All,
                    ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;

Then, I can get the accurate RemoteIpAddress now.

@exileDev
Copy link
Contributor

exileDev commented Jan 24, 2023

Couldn't reproduce. Closed #6486

@exileDev exileDev closed this as not planned Won't fix, can't repro, duplicate, stale Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants