2010-06-01 42 views
0

我正在創建一個自定義包含方法(加載)來檢查文件是否存在。載入函數包含存在的文件或發送電子郵件以通知我斷開的鏈接(如果不存在)。我遇到的問題是如果包含文件包含服務器控件,它只是將它們顯示爲純文本。如果我試圖將包含文件添加到包含文件,這是一個問題。服務器控件上的Response.Write

Default.aspx中我有:

<% ResourceMngr.load("~/Includes/menu.inc"); %> 

在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); 
    } 
} 

所以,如果 「menu.inc」 還包括<% ResourceMngr.load("~/Includes/test.inc"); %>標籤,它只是打印出來以純文本格式而不是嘗試包含test.inc,而頁面上的所有其他html完全按照預期顯示。我如何讓我的包含文件具有服務器控件?

回答

2

我假設你來自一個經典的asp或php背景。包含asp.net不能以這種方式工作。你可能想看看一些基本的web表單或MVC教程,因爲要與框架的工作,而不是針對它:-)

特別

,查找如何使用用戶控件(即只是那些一的.ascx擴展名)

+0

當我嘗試使用用戶控件時,遇到了與以前相同的問題。例如<%@ Control Language =「C#」AutoEventWireup =「true」CodeFile =「menu.ascx.cs」Inherits =「Includes_menu」%>以明文形式出現在我的頁面頂部。我也嘗試了