One limitation of the Scheduled Task Manager is it does not support client side redirection. The following code easily supports redirection, so it may be useful in the task manager: public void PingUrl(string url) { // http://stackoverflow.com/questions/2972643/how-to-use-cookies-with-httpwebrequest var request = (System.Net.HttpWebRequest) System.Net.HttpWebRequest.Create(url); request.AllowAutoRedirect = true; // so HTTP 302 redirection is followed request.CookieContainer = new System.Net.CookieContainer(); // so that the client side redirection uses any cookies returned by original url // Retrieve HTML returned by website - perhaps not needed by Scheduled Task Manager // but necessary for the request to be sent using (var response = request.GetResponse()) using (var stream = response.GetResponseStream()) using (var reader = new StreamReader(stream)) { string pageText = reader.ReadToEnd(); } } public void test() { PingUrl("http://mydomain.com/pingme.aspx"); } Thanks, David
Thanks Frank. I put the PingUrl code into a page that the existing Task Scheduler pings, and this effectively works around the limitation of the current Task Scheduler, the end result is that a page requiring redirection can actually work with the Task Scheduler. Another limitation of the Task Scheduler is that it does not allow access to pages that require ASP.NET Forms authentication. This code performs that function: // Log user in // Source: http://www.codeproject.com/Articles/13872/Form-authentication-and-authorization-in-ASP-NET FormsAuthentication.SetAuthCookie("admin", false); // create non-persistent authentication cookie; replace 'admin' with name of user to login FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( "admin", // replace with name of user to login - note password is not required! false, // cookie is not persistent 10 // expires in 10 minutes ); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket)); Response.Cookies.Add(cookie); // Redirect to any page as an authenticated user Response.Redirect("~/PageThatRequiresLoggedInUser"); // <-- client side redirection, requires cookies to be accepted by the client I don't believe you can put the above code into the Task Scheduler manager, since it needs to run on the website being pinged. But it will help other users workaround the Task Manager limitation so that the end result is that a page requiring Form authentication can actually work with the Task Scheduler. Perhaps you could put this into a KnowledgeBase article or something.
Why? That might involve copying and maintaining a lot of code, when it is the same task that might be performing in an existing web application.