webadvanced / Orchard-SiteMap

SiteMap module for Orchard CMS
14 stars 21 forks source link

Null Exception when BaseUrl is empty #18

Open natebunton opened 10 years ago

natebunton commented 10 years ago

When the BaseUrl site setting is empty a null exception is thrown in the AdvancedSitemapService.cs (Master) or HomeController.cs (Orchard-1.3x Tag v1.6.0).

    private string GetRootPath()
    {
        var baseUrl = _siteService.GetSiteSettings().BaseUrl;
        if (!baseUrl.EndsWith("/"))
            baseUrl += "/";
        return baseUrl;
    }

baseUrl should be checked for null or empty. if empty, then use ApplicationRootUrl (Orchard.Utility.Extensions)

    private string GetRootPath() {
        var baseUrl = _siteService.GetSiteSettings().BaseUrl;

        // If Base Url is not set, use the Request Application Root Url
        if (string.IsNullOrEmpty(baseUrl))
        {
            baseUrl = HttpContext.Request.ToApplicationRootUrlString();
        }

        if (!baseUrl.EndsWith("/"))
            baseUrl += "/";
        return baseUrl;
    }

I am using the Module from the Orchard Gallery, which looks like it is on branch Orchard-1.3x tag v1.6.0