{"id":3646,"date":"2014-03-29T07:25:00","date_gmt":"2014-03-29T07:25:00","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/29\/nopcommerce-on-appharbor-redirect-loop-collection-of-common-programming-errors\/"},"modified":"2014-03-29T07:25:00","modified_gmt":"2014-03-29T07:25:00","slug":"nopcommerce-on-appharbor-redirect-loop-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/29\/nopcommerce-on-appharbor-redirect-loop-collection-of-common-programming-errors\/","title":{"rendered":"nopCommerce on AppHarbor. Redirect loop-Collection of common programming errors"},"content":{"rendered":"<p>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.<\/p>\n<p>First, @TroelsThomsen fix in Webhelper.cs:75<\/p>\n<pre><code>public virtual string GetThisPageUrl(bool includeQueryString, bool useSsl)\n        {\n            string url = string.Empty;\n            if (_httpContext == null)\n                return url;\n\n            if (includeQueryString)\n            {\n                string storeHost = GetStoreHost(useSsl);\n                if (storeHost.EndsWith(\"\/\"))\n                    storeHost = storeHost.Substring(0, storeHost.Length - 1);\n                url = storeHost + _httpContext.Request.RawUrl;\n            }\n            else\n            {\n#if DEBUG\n                var uri = _httpContext.Request.Url;\n\n#else\n                \/\/Since appharbor changes port number due to multiple servers, we need to ensure port = 80 as in AppHarborRequesWrapper.cs\n                var uri = new UriBuilder\n                {\n                    Scheme = _httpContext.Request.Url.Scheme,\n                    Host = _httpContext.Request.Url.Host,\n                    Port = 80,\n                    Path = _httpContext.Request.Url.AbsolutePath,\n                    Fragment = _httpContext.Request.Url.Fragment,\n                    Query = _httpContext.Request.Url.Query.Replace(\"?\", \"\")\n                }.Uri;\n#endif\n                url = uri.GetLeftPart(UriPartial.Path);\n            }\n            url = url.ToLowerInvariant();\n            return url;\n        }\n<\/code><\/pre>\n<p>So what we did is simply add files from https:\/\/gist.github.com\/1158264 into Nop.Core\\AppHarbor<\/p>\n<p>and modified base controllers:<\/p>\n<ul>\n<li>\n<p>nopcommerce\\Presentation\\Nop.Web\\Controllers\\BaseNopController.cs<\/p>\n<pre><code>public class BaseNopController : Controller\n{\n    protected override void Initialize(RequestContext requestContext)\n    {\n        \/\/Source: https:\/\/gist.github.com\/1158264\n        base.Initialize(new RequestContext(new AppHarborHttpContextWrapper(System.Web.HttpContext.Current),\n                                           requestContext.RouteData));\n    }\n    \/\/Same file from here downwards...\n}\n<\/code><\/pre>\n<\/li>\n<li>\n<p>nopcommerce\\Presentation\\Nop.Web.Admin\\Controllers\\BaseNopController.cs<\/p>\n<pre><code>public class BaseNopController : Controller\n{\nprotected override void Initialize(System.Web.Routing.RequestContext requestContext)\n{\n    \/\/set work context to admin mode\n    EngineContext.Current.Resolve().IsAdmin = true;\n\n    \/\/Source: https:\/\/gist.github.com\/1158264\n    base.Initialize(new RequestContext(new AppHarborHttpContextWrapper(System.Web.HttpContext.Current), requestContext.RouteData));\n\n    \/\/base.Initialize(requestContext);\n}\n    \/\/Same file from here downwards...\n}\n<\/code><\/pre>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>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 = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3646","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3646","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3646"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3646\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3646"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3646"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3646"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}