2012-06-06 23 views
5

Uygulamamın fiziksel kökünü ve göreli kökünü uygulama başlatılırken bellekte depolamaya çalışıyorum. Global.Asax uygulamasında göreceli kökü alma

Ben fiziksel yol şöyle yaptı:

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

Ama göreli yolu alınamıyor. Ben çalışan Aşağıdaki kodu var, ama buna bir page nesne koymak gerektirir:

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

Teşekkür

cevap

1

Global.asax içinde aşağıdaki kodu ekleyin:

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; 
     } 
    } 
3

amacıyla application_start içinde göreli bir yol almak için aşağıdakileri kullanın:

protected void Application_Start(object sender, EventArgs e) 
{ 
    string path = Server.MapPath("/"); 
}