2012-10-05 42 views
0

我想創建一個簡單的服務,使其他應用程序可以輪詢的網址,例如閱讀並返回純asp.net文件內容?

http://IP/serverstatus.aspx 

而在單行線,沒有「HTML」獲取狀態。但我該如何輸出,我正在讀取文件的C#代碼中的文件,以及它將要輸出的文件中的內容。

+0

是你的問題相關['WebRequest'(http://msdn.microsoft.com/en-us/library/system.net.webrequest.aspx)? –

回答

2
  • 設置的ContentType
  • 清除響應(我認爲這是可選的)
  • 寫入響應
  • 確保您的ASPX文件爲空

像這樣:

protected void Page_Load(object sender, EventArgs e) 
{ 
    Response.ContentType = "text/plain"; 
    Response.Clear(); 
    Response.WriteFile(Server.MapPath("yourfile.txt")); 
} 
0

設置響應頭以純文本

0

嘗試:

Response.Write("hello world"); 
Response.End();