基本上我們分發給客戶端的一個web應用程序,其中一個將試用它,所以我需要能夠在某個特定點關閉它。不想把結束日期放在web.config中,以防萬一他們可以改變它,我正在考慮在global.asax中加入一些硬編碼的日期,但是我不確定我可以'關閉'應用程序。我正在考慮在驗證請求部分中檢查日期,並簡單地重定向到說明您的試驗已完成(或類似情況)的頁面,但有沒有更好的方法?使一個asp.netnet應用程序離線
3
A
回答
3
你可以做到這一點上global.asax
爲:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
if(DateTime.UtcNow > cTheTimeLimitDate)
{
HttpContext.Current.Response.TrySkipIisCustomErrors = true;
HttpContext.Current.Response.Write("...message to show...");
HttpContext.Current.Response.StatusCode = 403;
HttpContext.Current.Response.End();
return ;
}
}
這比其放置在web.config中更安全,但沒有什麼是足夠安全的。它甚至更好地將它們重定向到一個頁面,或者不向他們顯示消息,或者你認爲的任何東西。
對於化妝重定向到一個頁面,你還需要檢查,如果呼叫如果一個頁面,該代碼如下:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
string cTheFile = HttpContext.Current.Request.Path;
string sExtentionOfThisFile = System.IO.Path.GetExtension(cTheFile);
if (sExtentionOfThisFile.Equals(".aspx", StringComparison.InvariantCultureIgnoreCase))
{
// and here is the time limit.
if(DateTime.UtcNow > cTheTimeLimitDate)
{
// make here the redirect
HttpContext.Current.Response.End();
return ;
}
}
}
要真是難上加難,你可以自定義BasePage的那所有頁面都來自它(而不是來自System.Web.UI.Page
),並且您在頁面渲染上放置了限制 - 或者在每個頁面渲染的頂部顯示一條消息,結束時間。
public abstract class BasePage : System.Web.UI.Page
{
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
if(DateTime.UtcNow > cTheTimeLimitDate)
{
System.IO.StringWriter stringWriter = new System.IO.StringWriter();
HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
// render page inside the buffer
base.Render(htmlWriter);
string html = stringWriter.ToString();
writer.Write("<h1>This evaluation is expired</h1><br><br>" + html);
}
else
{
base.Render(writer);
}
}
}
0
只需添加app_offline.htm,您甚至可以爲您的用戶創建一條好消息。此外,將網站重新聯機非常容易,只需刪除或重命名app_offline.htm即可。
http://weblogs.asp.net/dotnetstories/archive/2011/09/24/take-an-asp-net-application-offline.aspx
相關問題
- 1. PhoneGap:離線應用程序使用
- 2. 離線使用Firebase Angular應用程序
- 3. 離線Web應用程序
- 4. 鈦離線應用程序
- 5. Angular應用程序離線
- 6. 使用sqlite離子應用程序離線保存圖像
- 7. 當用戶離線時運行離線網絡應用程序
- 8. 開發一個離線MathJax Android移動應用程序
- 9. Android信使應用程序:用戶在線/離線狀態
- 10. XAF應用程序的離線移動應用程序
- 11. 編寫應用程序離線工作(Web應用程序)
- 12. WordPress應用程序backebd,離線
- 13. Backbone.js在離線應用程序中
- 14. iOS和基本離線應用程序
- 15. Chrome應用程序離線模式
- 16. Sencha觸摸應用程序在離線
- 17. 離線應用程序快捷方式
- 18. Google Drive移動離線應用程序
- 19. Windows 8.1應用程序離線登錄
- 20. 離線網頁應用程序+ ipad bug
- 21. iPad應用程序或離線網站
- 22. Ember.js應用程序離線行爲
- 23. HTML5和離線移動應用程序
- 24. 在asp.net中的離線應用程序
- 25. 離線應用程序 - 數據庫
- 26. 桌面或離線Web應用程序?
- 27. Windows 8應用程序,Bing Maps離線
- 28. Iphone應用程序的離線地圖
- 29. 安全離線html5/js-應用程序?
- 30. Rails測試離線應用程序
你的意思是說,你會不會收留了它與您的客戶將託管代碼本身? – Ramesh
該應用安裝在客戶端服務器上 – user1166905
如果您嘗試創建'app_offline.html',則用戶可以刪除在該處創建文件的權限,這樣他們就可以避免這種情況。 – Aristos