2012-06-06 12 views
5

मैं एप्लिकेशन स्टार्टअप पर स्मृति में अपने आवेदन की भौतिक जड़ और सापेक्ष जड़ को स्टोर करने की कोशिश कर रहा हूं।ग्लोबल में सापेक्ष रूट प्राप्त करना। एएसएक्स

मैं तो जैसे भौतिक पथ किया:

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

लेकिन मैं रिश्तेदार पथ नहीं मिल सकता है। मैं निम्नलिखित कोड है कि काम करता है, लेकिन यह है कि यह एक page वस्तु में डाल करने की आवश्यकता है:

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

धन्यवाद

उत्तर

1

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

आदेश में application_start के भीतर एक सापेक्ष पथ प्राप्त करने के लिए निम्न का उपयोग करें:

protected void Application_Start(object sender, EventArgs e) 
{ 
    string path = Server.MapPath("/"); 
} 
संबंधित मुद्दे