我有 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/