Reputation: 65
I am trying to limit an asp.net site to only be accessible between 8:00am and 5:00pm. If I add this to the Global.asax.cs file it works great. However at 5:00pm I get this page Server Error
403 - Forbidden: Access is denied. You do not have permission to view this directory or page using the credentials that you supplied. How can I redirect to an Error Page?
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);
}
}
}
Just added this and it works
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"); } }
Upvotes: 0
Views: 202
Reputation: 3763
In your Global.asax add this line .
void Application_BeginRequest(object sender, EventArgs e)
{
if() //check your condition
HttpContext.Current.RewritePath("your html file");
}
Upvotes: 1
Reputation: 1599
This is just to address the error you are getting. This has nothing to do with making the site accessible for a specific time!.
One way to do that is through IIS.
Open IIS, locate your site click Error Pages, which will open a new window, you should see the status codes with the associated error pages.
Since you are getting a 403 error, make sure to modify that to your custom error page.
Just out of curiosity. Why would you make the site only accessible at specific times? You sure know that is a server time and it can be different than client's time.
Upvotes: 1