2017-11-17 35 views
5

मैं इस फ़ाइल संरचना की तर्ज पर कुछ के साथ एक ASP.NET WebForms अनुप्रयोग है: यदि मैं locahost/subfolder/page.aspx पर जाकर page.aspx का उपयोगWeb.config जब पेज मार्गों का उपयोग कर काम नहीं करता है

root\ 
    default.aspx 
    web.config 
    subfolder\ 
    page.aspx 
    web.config 

यह subfolder में web.config बस ठीक है।

हालांकि, मैं तो जैसे पृष्ठ सेटअप के लिए एक मार्ग है:

protected void Application_Start(object sender, EventArgs e) 
{ 
    RegisterRoutes(RouteTable.Routes); 
} 

public void RegisterRoutes(RouteCollection routes) 
{ 
    routes.MapPageRoute("", "test", "~/subfolder/page.aspx"); 
} 

और जब मुझे लगता है कि मार्ग के माध्यम से पेज तक पहुँचने के लिए, localhost/test पर जाकर कोशिश, पृष्ठ लोड ठीक, लेकिन यह करने में विफल रहता उप फ़ोल्डर में web.config से मान पढ़ें।

क्या मुझे कुछ याद आ रही है? क्या sub web.config मार्गों के साथ काम करने की अनुमति देने के लिए कोई और कदम है?

protected void Application_BeginRequest(object sender, EventArgs e) 
{ 
    HttpRequest request = HttpContext.Current.Request; 
    Route route = RouteTable.Routes.Where(x => (x as Route)?.Url == request.Url.AbsolutePath.TrimStart('/')).FirstOrDefault() as Route; 
    if (route != null) 
    { 
     if (route.RouteHandler.GetType() == typeof(PageRouteHandler)) 
     { 
      HttpContext.Current.RewritePath(((PageRouteHandler)route.RouteHandler).VirtualPath, request.PathInfo, request.Url.Query, false); 
     } 
    } 
} 

करने से:

var test = WebConfigurationManager.AppSettings["testSetting"]; 

उत्तर

3

मैं अपने Global.asax के लिए निम्न जोड़कर मेरी इस मुद्दे को हल कर लिया है:

मैं उप web.config का उपयोग कर रहा हूँ तक पहुँचने यह, मैं अनुरोध पृष्ठ की यूआरएल संपत्ति को पृष्ठ पर "वास्तविक" यूआरएल का उपयोग करने के लिए किसी मौजूदा पृष्ठ मार्ग से मेल खाने वाले यूआरएल के अनुरोध के लिए नकली करता हूं। इस तरह, जब WebConfigurationManager कॉन्फ़िगरेशन खींचता है (जो वर्तमान वर्चुअल पथ द्वारा करता है), तो यह उचित पृष्ठ का उपयोग करके इसे खींचता है।

संबंधित मुद्दे