나는이 파일 구조의 라인을 따라 뭔가가있는 ASP.NET 웹폼 응용 프로그램이 : 나는 locahost/subfolder/page.aspx
로 이동하여 page.aspx
에 액세스하는 경우의 Web.config 작동하지 않습니다
root\
default.aspx
web.config
subfolder\
page.aspx
web.config
을 하위 폴더에서 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에서 값을 읽으십시오.
내가 누락 된 항목이 있습니까? 하위 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);
}
}
}
함으로써 : 나는 내 Global.asax에에 다음을 추가하여 내 문제를 해결 할 수있었습니다
var test = WebConfigurationManager.AppSettings["testSetting"];