【问题标题】:nopCommerce on AppHarbor. Redirect loopAppHarbor 上的 nopCommerce。重定向循环
【发布时间】:2012-01-27 16:02:42
【问题描述】:

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

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

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

StartsWith 比较总是错误的,因为 GetThisPageUrl 返回 http://[name].apphb.com:14275/install

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

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

【问题讨论】:

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


    【解决方案1】:

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

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

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

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

    【讨论】:

    • 我通过正则表达式删除了端口,感谢您的建议。修复了这个问题,但还有十几个其他问题。我想我要中止在 AppHarbor 上使用 Nop 进行的实验
    【解决方案2】:

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

    首先,@TroelsThomsen 在 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\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...
      }
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-19
      • 2015-02-04
      • 1970-01-01
      相关资源
      最近更新 更多