AppHarbor上的nopCommerce。重定向循环

时间:2011-12-25 16:56:25

标签: asp.net asp.net-mvc nopcommerce appharbor

我正在尝试将nopCommerce应用程序部署到AppHarbor。

当我启动页面时,我遇到了运行时重定向循环。我添加了一些调试日志记录,问题似乎是Global.asax.cs中的这一部分 - > EnsureDatabaseIsInstalled():

if (!webHelper.GetThisPageUrl(false).StartsWith(installUrl, StringComparison.InvariantCultureIgnoreCase))
            {
                this.Response.Redirect(installUrl);
            }

StartsWith比较始终为false,因为 GetThisPageUrl返回 http://[name].apphb.com:14275/install

和installUrl(通过GetStoreLocation)返回 http://[name].apphb.com/install

有没有人能够让nopCommerce与AppHarbor一起工作?

2 个答案:

答案 0 :(得分:6)

看起来您需要修改nopCommerce以省略端口号。我快速浏览了一下源代码,似乎有两种可能的解决方案:

1)在false方法中将布尔参数从true更改为EnsureDatabaseIsInstalled应该会导致GetThisPageUrl方法选择生成不带端口的URL的其他分支号。

2)更新GetThisPageUrl方法(“WebHelper.cs”)中的else分支以忽略端口号。

选择第一个解决方案会更容易,但是将问题修补到核心位置会更好,因此您不会遇到类似的问题。

答案 1 :(得分:2)

除了@TroelsThomsen修复,我们在基本控制器中使用了一个包装器,以确保我们的所有代码都无法更改appharbor端口。

首先,@ TroelThomsen修复Webhelper.cs:75

public virtual string GetThisPageUrl(bool includeQueryString, bool useSsl)
        {
            string url = string.Empty;
            if (_httpContext == null)
                return url;

            if (includeQueryString)
            {
                string storeHost = GetStoreHost(useSsl);
                if (storeHost.EndsWith("/"))
                    storeHost = storeHost.Substring(0, storeHost.Length - 1);
                url = storeHost + _httpContext.Request.RawUrl;
            }
            else
            {
#if DEBUG
                var uri = _httpContext.Request.Url;

#else
                //Since appharbor changes port number due to multiple servers, we need to ensure port = 80 as in AppHarborRequesWrapper.cs
                var uri = new UriBuilder
                {
                    Scheme = _httpContext.Request.Url.Scheme,
                    Host = _httpContext.Request.Url.Host,
                    Port = 80,
                    Path = _httpContext.Request.Url.AbsolutePath,
                    Fragment = _httpContext.Request.Url.Fragment,
                    Query = _httpContext.Request.Url.Query.Replace("?", "")
                }.Uri;
#endif
                url = uri.GetLeftPart(UriPartial.Path);
            }
            url = url.ToLowerInvariant();
            return url;
        }

所以我们所做的只是将https://gist.github.com/1158264中的文件添加到Nop.Core \ AppHarbor

和修改过的基本控制器:

  • nopcommerce \演示\ Nop.Web \控制器\ BaseNopController.cs

    public class BaseNopController : Controller
    {
        protected override void Initialize(RequestContext requestContext)
        {
            //Source: https://gist.github.com/1158264
            base.Initialize(new RequestContext(new AppHarborHttpContextWrapper(System.Web.HttpContext.Current),
                                               requestContext.RouteData));
        }
        //Same file from here downwards...
    }
    
  • nopcommerce \演示\ Nop.Web.Admin \控制器\ BaseNopController.cs

    public class BaseNopController : Controller
    {
    protected override void Initialize(System.Web.Routing.RequestContext requestContext)
    {
        //set work context to admin mode
        EngineContext.Current.Resolve<IWorkContext>().IsAdmin = true;
    
        //Source: https://gist.github.com/1158264
        base.Initialize(new RequestContext(new AppHarborHttpContextWrapper(System.Web.HttpContext.Current), requestContext.RouteData));
    
        //base.Initialize(requestContext);
    }
        //Same file from here downwards...
    }