[聚合文章] asp.net ckfinder 图片不同host路径问题

c# 2015-05-07 6 阅读

首先获取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 + @"ckfinder\userfiles\";

注:本文内容来自互联网,旨在为开发者提供分享、交流的平台。如有涉及文章版权等事宜,请你联系站长进行处理。