如何在asp.net中阻止基于日期的web应用程序?

如何在asp.net中阻止基于日期的web应用程序?,asp.net,Asp.net,我已经在asp.net中为我的客户开发了一个web应用程序。该应用程序已托管在web服务器中。如果我的客户机不满足我的要求,我想根据日期阻止该web应用程序从服务器上运行。如何进行该测试?您可以使用应用程序\u BeginRequest进行该测试,如下所示: protected void Application_BeginRequest(Object sender, EventArgs e) { string cTheFile = HttpContext.Current.Request.P

我已经在asp.net中为我的客户开发了一个web应用程序。该应用程序已托管在web服务器中。如果我的客户机不满足我的要求,我想根据日期阻止该web应用程序从服务器上运行。如何进行该测试?

您可以使用
应用程序\u BeginRequest
进行该测试,如下所示:

protected void Application_BeginRequest(Object sender, EventArgs e)
{
   string cTheFile = HttpContext.Current.Request.Path;
   string sExtentionOfThisFile = System.IO.Path.GetExtension(cTheFile);
   // here you can check what file you wish to cut, ether by file, ether by extention
   if (sExtentionOfThisFile.Equals(".aspx", StringComparison.InvariantCultureIgnoreCase))
   {
     // and here is the time limit.
     if(DateTime.UtcNow > MaxDateToUse)
     {
        HttpContext.Current.Response.TrySkipIisCustomErrors = true;
        HttpContext.Current.Response.StatusCode = 403;
        HttpContext.Current.Response.End();
        return ;    
    }    
  }
}
在一个基本页中添加相同的测试对所有页面使用该基本页,并在那里进行测试,正如我在回答中所描述的:

相对: