मैं इस फ़ाइल संरचना की तर्ज पर कुछ के साथ एक 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"];