Twitter

Facebook

Umbraco Certified

RAR Recommended

Twitter

Thu 17 May 12 @ 7:06JetBrains dotPeek 1.0 has just been released http://t.co/q0toNbzY

Wed 16 May 12 @ 8:53Grew up in the 1980's? Take a trip down memory lane http://t.co/nFPqtLtH #1980s #memories

Tue 15 May 12 @ 8:30What a cool idea for a piggy bank http://t.co/IN08jLi2

Follow Us On Twitter

nopCommerce Solution Provider

Microsoft Partner Network

Archive

View All

Running NopCommerce With SSL Through EC2 ELB

Thursday, September 08, 2011

If you are running your hosting environment on Amazon EC2 and have multiple nopCommerce sites setup, you will have no doubt got your ELB setup with a valid SSL certificate then enabled 'UseSSL' in the NopCommerce web.config.

Only to fire up the site, and find if you try to go to a secure page the site ends up in a endless loop!  This is because the 'IsCurrentConnectionSecured()' method in the 'CommonHelper' class will not work and 'Request.IsSecureConnection' as it will never return true (As the SSL termination is handled on the ELB).  There is a commented section in this method, which states if you are in a load balanced environment to uncomment and use instead of the current 'Request.IsSecureConnection' call.

Unfortunately this is for sharedSSL setups on hosting environments like GoDaddy, and also will not work - Below is the amended method, which will let you use nopCommerce with SSL on with your secure ELB.

/// <summary>
/// Gets a value indicating whether current connection is secured
/// </summary>
/// <returns>true - secured, false - not secured</returns>
public static bool IsCurrentConnectionSecured()
{
    var useSSL = false;
    if (HttpContext.Current != null && HttpContext.Current.Request != null)
    {

        //useSSL = HttpContext.Current.Request.IsSecureConnection;
        //when your hosting uses a load balancer on their server then the Request.IsSecureConnection is never got set to true, use the statement below
        //just uncomment it
        //useSSL = HttpContext.Current.Request.ServerVariables["HTTP_CLUSTER_HTTPS"] == "on" ? true : false;
        useSSL = HttpContext.Current.Request.Headers["X-FORWARDED-PROTO"].ToLower() == "https";
    }

    return useSSL;
}

Hopefully this will save someone else the hours I spent trying to find why the store wouldn't work!