Skip to content

Null Exception when BaseUrl is empty #18

@natebunton

Description

@natebunton

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions