I am creating a custom include method (load) to check if a file exists. The load function includes the file if it exists or sends an email to notify me of a broken link if it doesn't. The problem I am having is if the include file contains server controls, it just displays them as plain text. This is a problem if I were to try to add an include file to an include file.
In default.aspx I have:
<% ResourceMngr.load("~/Includes/menu.inc"); %>
In ResourceMngr:
public static void load(String url) {
string file = HttpContext.Current.Server.MapPath(url);
if (System.IO.File.Exists(file))
{
HttpContext.Current.Response.Write(System.IO.File.ReadAllText(file));
}
else
{
String body = "This message was sent to inform you that the following includes file is missing: \r\n";
body += "Referrer URL: " + HttpContext.Current.Request.Url.AbsoluteUri + "\r\n";
body += "File Path: " + file;
MailUtil.SendMail("[email protected]", "Missing Includes File", body);
}
}
So, if "menu.inc" also includes a <% ResourceMngr.load("~/Includes/test.inc"); %>
tag, it just prints it out in plain text on the page instead of trying to include test.inc while all the other html on the page shows up exactly as expected. How would I allow my include file to have server controls?