简体   繁体   中英

Is there a way for me to schedule a 302 redirect in IIS or web.config?

I have some websites that need to be set to 302 redirect at midnight of a specific date. I understand that I can setup the redirects through IIS or through web.config for the site, but both of those would require me to make the change by hand at midnight as I understand it. Is there any way for me to setup ahead of time for the redirect to begin at a future date?

You could do a redirect in the global.asax file.

protected void Application_Start(Object sender, EventArgs e) {
    DateTime dateToRedirect = new DateTime(2015, 4, 1);
    HttpContext context = HttpContext.Current;

    if(DateTime.Now > dateToRedirect)
    {
        if(...) // Conditional code for setting which pages get redirected
        {
            string newUrl = "http://www.example.com";
            context.Response.Redirect(newUrl);
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM