AppHarbor NopCommerce运行问题

时间:2011-10-31 14:04:04

标签: nopcommerce appharbor

我将nopcommerce解决方案上传到appharbor(使用此方法Can't build notcommerce project under appharbor)并成功构建了解决方案,但我收到403错误 - 禁止访问:尝试打开页面时拒绝访问(允许对文件系统进行写访问权限)真的)。

感谢并希望得到您的帮助

3 个答案:

答案 0 :(得分:2)

问题是标准的NopCommerce解决方案包含两个Web项目。 AppHarbor每个应用程序只部署一个Web项目,在这种情况下,我们碰巧部署了Nop.Admin,这不是您想要的。

要解决此问题,您应该利用AppHarbor solution file convention并创建仅引用AppHarbor.sln项目的Nop.Web解决方案文件。

答案 1 :(得分:2)

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

首先,修复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...
    }
    

答案 2 :(得分:1)

启用IIS Express中的目录浏览功能

注意此方法适用于在使用IIS Express时遇到问题的Web开发人员。

为此,请按照下列步骤操作: 打开命令提示符,然后转到计算机上的IIS Express文件夹。例如,在命令提示符中转到以下文件夹: C:\ Program Files \ IIS Express 键入以下命令,然后按Enter键: appcmd set config / section:directoryBrowse / enabled:true

参考:https://support.microsoft.com/en-us/kb/942062