Scheduled Task and Redirect Problems

Discussion in 'ASP.NET 2.0' started by pinch, Jun 9, 2008.

  1. I have some code that needs to run every few hours so I've tried to schedule a task to hit a certain page of my website. The page to be called has no code except for a single method call in the Page_Load event which does some DB cleanup. However, I cannot get this to work using the Schedule Task tool.

    From Tech Support:
    My problem is that when the httprequest is sent to my page from the Schedule Task tool, a redirect is occurring and my code is never being run (even though there is no code on the page itself, certainly no redirects).

    However, if I navigate to this page directly in my browser, all is fine and the code runs perfectly. So, it appears that when the Schedule Task tool access this page, somehow my application is performing a redirect and the Scheduled Task never waits around to run the necessary code. Tech Support sent me the result of a telnet session and it displayed the following:


    GET http://cheatsheetw.web128.discountasp.net/Cleanup.aspx HTTP/1.0

    HTTP/1.1 302 Found
    Connection: close
    Date: Fri, 06 Jun 2008 18:14:44 GMT
    Server: Microsoft-IIS/6.0
    X-Powered-By: ASP.NET
    X-AspNet-Version: 2.0.50727
    Location: /Cleanup.aspx?AspxAutoDetectCookieSupport=1
    Set-Cookie: AspxAutoDetectCookieSupport=1; path=/
    Cache-Control: private
    Content-Type: text/html; charset=utf-8
    Content-Length: 170

    <html><head><title>Object moved</title></head>
    <h2>Object moved to <a href='/Cleanup.aspx?AspxAutoDetectCookieSupport
    =1'>here</a>.</h2>
    </body></html>

    Connection to host lost.


    After reviewing this code I thought it may have something to do with the fact that my settings for cookies: <forms cookieless='AutoDetect'> so I changed this to <forms cookieless='UseCookies'>. Even after this change, tech support said that they're still getting a redirect from my page which is resulting in my code not being run. As I said before my page has nothing on it and I have a single method call in my Page_Load event, but because of the redirect my code isn't being run. I'm using forms authentication, but this page is not protected by any authorization rules.

    I'm really at a loss here as to why a redirect is occurring. Any ideas? Am I using the Task Scheduler incorrectly?

    Post Edited (pinch) : 6/9/2008 3:38:03 PM GMT
     
  2. Set
    <sessionState
    cookieless="true"

    <forms
    cookieless="true"

    and try site page in IE

    Best regards

    Alexei Cioina.
     
  3. 'true' is not a valid property for cookieless in <forms> and I am using cookies to retain session so I can't set cookieless to 'true' in <sessionState> either.

    As I said before, the code works fine when I visit the page in my browser, it is when the page is called the the Task Scheduler that the problem occurs.


    Tech Support said they cannot help me further; is there any way to run a TELNET test myself, similar to what they did to determine if that cookie-related GET data is still present?
     
  4. Are you sure that DASP robot (bot) use cookies?
     
  5. The scheduled task bot is not equivalent to a browser. It has no cookie or session retention capability. It simply makes the http call and moves on. So your page must not be protected by forms authentication, nor rely on session data, nor havea redirect. I recommend placing the page in a separate folder with Windows authentication enabled instead. You can protect the page with the Permission Manager in your DiscountASP control panel.
     
  6. -I am using forms authentication for my application, but this particular page is not protected by authorization rights (you don't have to login to view it). Is that what you mean?
    -The page does not rely on session data
    -There is no code on the page so it can't possibly have a redirect.

    So your suggestion is to:

    1. Move this page to its own folder
    2. Turn on windows authentication for this folder (through a web.config?)
    3. Protect that page with the Permission Manager.

    ?
     
  7. The redirects are done automatically by the app because of the ASP.NET forms authenticatication feature, even if you have allowed access. So, yes put a web.config specifying windows authentication in the new folder.
     
  8. I'm having a bit of trouble with your suggested solution; seems that only one authentication mode is allowed per application. Since I'm already using forms authentication, I tried to implement your suggestion:

    1. Created a new directory called ScheduledTask under the main application root.
    2. Added a web.config file to that new directory and configured it:


    <configuration>
    <system.web>
    <authentication mode='Windows'>
    </authentication>
    </system.web>
    </configuration>

    But the website will not build because of the <authentication> tag listed here.

    Are you saying that for a web application with forms authentication, every time a request is made for a page a redirect occurs, even if that page isn't protected by authorization rules?

    I'm thoroughly confused now. Honestly I just want to call a method every couple of hours, nothing too complicated, but this is a mess.

    Not sure how to proceed...

    Post Edited (pinch) : 6/10/2008 9:15:35 PM GMT
     
  9. hi pinch,

    I think I have the same problem with my scheduled task not working on my page. When I view the page myself through a browser, the method in the code behind is called. But when the scheduled task is run, it's not hitting the page, and the method is never called.

    Did you ever figure out the solution?
     
  10. Hi dstylez,

    Unfortunately I wasn't able to get one iota of help from DASP for my problem with this issue. When I tried to get help through a support ticket, they once gave me some debug information then on subsequent pings they repeatedly told me that they would not help me and I'd have to get assistance in the forums. I explained to them that I was getting no help in the forums and they again directed me to the forums. IMO, if you advertise a feature (such as the Schedul Task tool) at the very least I'd expect to see one piece of sample code illustrating how to use the tool, but there is nothing in the knowledge base. When I asked them for some sample code through the support ticket, they again directed me to the forums. /emoticons/shakehead.gif

    Unable to get help from DASP I tried to get help from some other folks over at Sitepoint and they disagreed with the what DASP was telling me. I was going to attempt to respond to my support ticket again with some further question but sorta knew the response that I'd get.

    Here is that thread from Sitepoint if you're interested: www.sitepoint.com/forums/showthread.php?t=553339&highlight=redirect

    Unable to get any help from DASP, unable to even figure out how to use the feature, and at my wit's end after weeks of searching for a solution, I finally developed an alternate solution using SQL triggers. I'm still not sure how to use the Schedule Task tool.
     

Share This Page