基本上我们分发给客户端的一个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