asp.net - 关闭.net服务中的所有功能

标签 asp.net web-services

我有 ASP.NET Web 服务项目。如果当前时间在 00:00 和 01:00 之间,我必须“关闭”(返回 void 或 null)此服务中的所有方法。最好的方法是什么?可能是 global.asax 文件?

最佳答案

您可以在 Global.asax 上的 Application_BeginRequest 上执行此操作,只需检查是否是 Web 服务,然后如果不允许该时间,则可以将其删除。

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(".asmx", StringComparison.InvariantCultureIgnoreCase))
   {
     // and here is the time limit.
     if(DateTime.UtcNow.Hour >= 0 && DateTime.UtcNow.Hour <= 1)
     {
        HttpContext.Current.Response.TrySkipIisCustomErrors = true;
        HttpContext.Current.Response.StatusCode = 403;
        HttpContext.Current.Response.End();
        return ;    
    }    
  }
}

关于asp.net - 关闭.net服务中的所有功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12777762/

相关文章:

javascript - 如何告诉 javascript 函数要操作什么元素?

javascript - 发布加载事件 Fullcalendar.io

java - Axis 2 和 Rampart 如何在 policy.xml 中仅指定传出安全性

c# - 如何在生命周期中删除客户端脚本资源?

mysql - vb.net 中的通用搜索框并从多个表中进行检查

web-services - ColdFusion WSDL 在第一次调用时超时

java - 无法创建 Java 客户端并将其连接到 C# WebService

windows - Web Service、WCF 和 Window Service 有什么区别?

java - 无法在 Netbeans 现有项目中创建 SOAP 客户端

c# - Entity Framework 树结构