2011-12-25 68 views
3

我想部署一个nopCommerce应用程序到AppHarbor。AppHarbor上的nopCommerce。重定向循环

当我开始页面时,我遇到了一个运行时重定向循环。我平添了几分调试日志记录和问题似乎是这部分中的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一起工作吗?

回答

6

它看起来像你需要修改nopCommerce来省略端口号。我参加了一个快速浏览一下源似乎有两种可能的解决方案:

1)在EnsureDatabaseIsInstalled方法改变从false boolean变量,以true应引起GetThisPageUrl方法来选择不同的分支,生成URL,而不端口号。

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

挑选第一个解决方案比较容易,但在其核心部分修补问题会更好,因此您不会遇到类似的问题。

+0

我通过正则表达式感谢您的建议移除的端口。解决了这个问题,但有大约十几个人。我想我会放弃在AppHarbor上使用Nop的实验 – chg 2011-12-26 10:34:06

2

除了@TroelsThomsen修补程序,我们在我们的基础控制器中使用包装程序来确保我们的所有代码都不会忽略端口改变。

首先,@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 \演示\ 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... 
    }