3

我正在尝试将 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 一起工作?

4

2 回答 2

6

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

1)在方法中将布尔参数从falseto更改应该会导致该方法选择一个不同的分支,该分支生成没有端口号的 URL。trueEnsureDatabaseIsInstalledGetThisPageUrl

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

选择第一个解决方案更容易,但在其核心修补问题会更好,这样您就不会遇到类似的问题。

于 2011-12-25T17:48:20.807 回答
2

In addition to @TroelsThomsen fix, we use a wrapper in our base controller to ensure that all of our code is oblivious to appharbor port changing.

First, @TroelsThomsen fix in 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;
        }

So what we did is simply add files from https://gist.github.com/1158264 into Nop.Core\AppHarbor

and modified base controllers:

  • nopcommerce\Presentation\Nop.Web\Controllers\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\Presentation\Nop.Web.Admin\Controllers\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...
    }
    
于 2012-04-08T16:40:15.730 回答