7

アプリケーションの起動時に、アプリケーションの物理ルートと相対ルートをメモリに保存しようとしています。

私はそのように物理的な道を歩みました:

    //Get the physical root and store it
    Global.ApplicationPhysicalPath = Request.PhysicalApplicationPath;

しかし、相対パスを取得できません。page動作する次のコードがありますが、オブジェクトに配置する必要があります。

Global.ApplicationRelativePath = Request.Url.AbsoluteUri.Replace(Request.Url.AbsolutePath, "") + Page.ResolveUrl("~/");

ありがとう

4

2 に答える 2

2

Global.asax に次のコードを追加します。

private static string ServerPath { get; set; }

protected void Application_BeginRequest(Object sender, EventArgs e)
    {
        ServerPath = BaseSiteUrl;
    }

    protected static string BaseSiteUrl
    {
        get
        {
            var context = HttpContext.Current;
            if (context.Request.ApplicationPath != null)
            {
                var baseUrl = context.Request.Url.Scheme + "://" + context.Request.Url.Authority + context.Request.ApplicationPath.TrimEnd('/') + '/';
                return baseUrl;
            }
            return string.Empty;
        }
    }
于 2013-02-18T11:01:53.690 に答える