i'm writing a code for making a site under maintenance.Can anyone help me please.the requirements are as follows.i have a project code i need to make that website go under maintenance from a specific time to specific time like example from 18 to before 8 it should be under maintenance and it should be done in global.asax file and start and end time should be like keys whose value is present webconfig file as shown below can any one please help me out?? code for global.aspx should be like dis...................
// Clear the response stream
var httpContext = HttpContext.Current;
httpContext.Response.Clear();
httpContext.ClearError();
httpContext.Response.TrySkipIisCustomErrors = true;
var routeData = new RouteData();
routeData.Values.Add("controller", "Error");
routeData.Values.Add("action", action);
// Call error Controller and pass the routeData.
using (var controller = new ErrorController())
{
((IController)controller).Execute(new RequestContext(new HttpContextWrapper(httpContext), routeData));
}
the key should be as follows...
<add key="StartTime" value="8"/>
<add key="EndTime" value="18"/>
the logic i have taken is as follows
public class UnderMaintenanceAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var requestTimestamp = filterContext.HttpContext.Timestamp;
if (IsUnderMaintenance(requestTimestamp))
{
filterContext.Result = new RedirectToRouteResult(
// create your controller/action/view to display your message
new RouteValueDictionary
{
{ "controller", "Undermaintenance" },
{ "action", "Index" }
});
}
}
private bool IsUnderMaintenance(DateTime requestTimestamp)
{
bool isUnderMaintenance = requestTimestamp.Hour >= 18 || requestTimestamp.Hour < 13;
return isUnderMaintenance;
}
}
but i have written that in route config my manager wants me to write it in global.aspx with start key and end key