asp.net ckfinder 圖片不同host路徑問題

Chobits發表於2019-02-16

首先獲取host -> http://stackoverflow.com/questions/689678/request-url-host-and-applica…

  public static string GetSiteRoot()
    {
        string port = System.Web.HttpContext.Current.Request.ServerVariables["SERVER_PORT"];
        if (port == null || port == "80" || port == "443")
            port = "";
        else
            port = ":" + port;

        string protocol = System.Web.HttpContext.Current.Request.ServerVariables["SERVER_PORT_SECURE"];
        if (protocol == null || protocol == "0")
            protocol = "http://";
        else
            protocol = "https://";

        string sOut = protocol + System.Web.HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + port + System.Web.HttpContext.Current.Request.ApplicationPath;

        if (sOut.EndsWith("/"))
        {
            sOut = sOut.Substring(0, sOut.Length - 1);
        }

        return sOut;
    }

之後在 ckfinder/config.ascx 配置路徑

// The base URL used to reach files in CKFinder through the browser.
BaseUrl = GetSiteRoot() + "/ckfinder/userfiles/";

// The phisical directory in the server where the file will end up. If
// blank, CKFinder attempts to resolve BaseUrl.
BaseDir = Request.PhysicalApplicationPath + @"ckfinderuserfiles";

相關文章