根据时间限制asp.net访问

时间:2015-11-14 01:14:11

标签: asp.net asp.net-mvc c#-4.0 visual-studio-2012

我试图限制一个asp.net网站只能在上午8:00到下午5:00之间访问。如果我将它添加到Global.asax.cs文件中,它可以很好地工作。但是在下午5点我得到此页面服务器错误

403 - 禁止访问:访问被拒绝。 您无权使用您提供的凭据查看此目录或页面。如何重定向到错误页面?

 public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {

        if (DateTime.Now.TimeOfDay > System.TimeSpan.Parse("08:00:00") & DateTime.Now.TimeOfDay < System.TimeSpan.Parse("17:06:00"))
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }

    }




}

刚添加此内容并且可以正常使用

 public ActionResult ReleaseBulk() { if (DateTime.Now.TimeOfDay > System.TimeSpan.Parse("08:00:00") & DateTime.Now.TimeOfDay < System.TimeSpan.Parse("00:06:00")) { return View(); } else { return RedirectToAction("Error", "Error"); } }

2 个答案:

答案 0 :(得分:1)

这只是为了解决您遇到的错误。这与使网站在特定时间内无法访问无关!

一种方法是通过IIS。

打开 IIS ,找到您的网站点击错误页面,这将打开一个新窗口,您应该会看到状态代码及相关的错误页面。

由于您收到 403 错误,请务必将其修改为自定义错误页面。

enter image description here

出于好奇。为什么您只能在特定时间访问该网站?您确定知道这是服务器时间,它可能与客户端的时间不同。

答案 1 :(得分:1)

在你的Global.asax中添加这一行。

$sql='select * from `clients`';
if( !is_null( $parm ) ) $sql.=' where `name`="'.$parm.'";';
相关问题