Can I cancel a running server page from the browser?

Discussion in 'ASP General' started by Larry Woods, Aug 11, 2003.

  1. Larry Woods

    Larry Woods Guest

    I have a server page that has served an HTML page with a "Cancel" button on
    it, BUT this server page has not completed and is running a 15-30 second
    process before it completes. I want the browser user to be able to
    terminate the page before the server process has finished. What I tried was
    an onClick event that issued a "location.href..." in hopes that this would
    load this referenced page, etc. but I have found that the browser waits
    until the server process had compled before executing the "location.href".
    Is there some way that I can "signal" the server to stop processing so that
    I can go to the "location.href" page; or is there some other way?

    TIA,

    Larry Woods
    Larry Woods, Aug 11, 2003
    #1
    1. Advertising

  2. "Larry Woods" wrote:
    >
    > I have a server page that has served an HTML page with a "Cancel"
    > button on it, BUT this server page has not completed and is running
    > a 15-30 second process before it completes. I want the browser user
    > to be able to terminate the page before the server process has
    > finished...
    > ...Is there some way that I can "signal" the server to stop
    > processing so that I can go to the "location.href" page; or is there
    > some other way?


    You cannot directly cancel the request. The best you can do is have the ASP
    process constantly monitor some independent entity (a session variable or a
    record in a DB, for example), continuing only if some prearranged condition
    is met. The cancel request would still be independent of the original
    request, but this should be possible in principle.


    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms. Please do not contact
    me directly or ask me to contact you directly for assistance. If your
    question is worth asking, it's worth posting.
    Dave Anderson, Aug 11, 2003
    #2
    1. Advertising

  3. Larry Woods

    Larry Woods Guest

    Thanks, Dave.

    What would be the best way to set a Session variable for the browser? A
    popup window ( 0 x 0 )?

    TIA,

    Larry

    "Dave Anderson" <> wrote in message
    news:...
    > "Larry Woods" wrote:
    > >
    > > I have a server page that has served an HTML page with a "Cancel"
    > > button on it, BUT this server page has not completed and is running
    > > a 15-30 second process before it completes. I want the browser user
    > > to be able to terminate the page before the server process has
    > > finished...
    > > ...Is there some way that I can "signal" the server to stop
    > > processing so that I can go to the "location.href" page; or is there
    > > some other way?

    >
    > You cannot directly cancel the request. The best you can do is have the

    ASP
    > process constantly monitor some independent entity (a session variable or

    a
    > record in a DB, for example), continuing only if some prearranged

    condition
    > is met. The cancel request would still be independent of the original
    > request, but this should be possible in principle.
    >
    >
    > --
    > Dave Anderson
    >
    > Unsolicited commercial email will be read at a cost of $500 per message.

    Use
    > of this email address implies consent to these terms. Please do not

    contact
    > me directly or ask me to contact you directly for assistance. If your
    > question is worth asking, it's worth posting.
    >
    >
    >
    >
    Larry Woods, Aug 11, 2003
    #3
  4. Use a hidden frame.
    http://www.aspfaq.com/2001
    http://www.aspfaq.com/2281


    "Larry Woods" <> wrote in message
    news:...
    > Thanks, Dave.
    >
    > What would be the best way to set a Session variable for the browser? A
    > popup window ( 0 x 0 )?
    >
    > TIA,
    >
    > Larry
    >
    > "Dave Anderson" <> wrote in message
    > news:...
    > > "Larry Woods" wrote:
    > > >
    > > > I have a server page that has served an HTML page with a "Cancel"
    > > > button on it, BUT this server page has not completed and is running
    > > > a 15-30 second process before it completes. I want the browser user
    > > > to be able to terminate the page before the server process has
    > > > finished...
    > > > ...Is there some way that I can "signal" the server to stop
    > > > processing so that I can go to the "location.href" page; or is there
    > > > some other way?

    > >
    > > You cannot directly cancel the request. The best you can do is have the

    > ASP
    > > process constantly monitor some independent entity (a session variable

    or
    > a
    > > record in a DB, for example), continuing only if some prearranged

    > condition
    > > is met. The cancel request would still be independent of the original
    > > request, but this should be possible in principle.
    > >
    > >
    > > --
    > > Dave Anderson
    > >
    > > Unsolicited commercial email will be read at a cost of $500 per message.

    > Use
    > > of this email address implies consent to these terms. Please do not

    > contact
    > > me directly or ask me to contact you directly for assistance. If your
    > > question is worth asking, it's worth posting.
    > >
    > >
    > >
    > >

    >
    >
    Aaron Bertrand - MVP, Aug 11, 2003
    #4
  5. Larry Woods wrote:
    >
    > I have a server page that has served an HTML page with a "Cancel" button on
    > it, BUT this server page has not completed and is running a 15-30 second
    > process before it completes.


    Long-running processes are not good for web servers. You should write
    this application a different way. See
    http://www.google.com/groups?hl=en&lr=&ie=UTF-8&selm=#eae9UZoCHA.1612@TK2MSFTNGP09
    for a better way.

    > I want the browser user to be able to
    > terminate the page before the server process has finished.


    Educate the user about the browser's "Stop" button. Alternatively the
    user can click on another URL, select a bookmark, or enter a new URL.
    When the Stop button is pressed, the TCP connection is reset and the
    connection closed between client browser and server. Any queued output
    will be discarded by whichever party (client, server or proxy agent) is
    holding it.

    Good Luck,
    Michael D. Kersey
    Michael D. Kersey, Aug 11, 2003
    #5
  6. Larry Woods

    Larry Woods Guest

    The application is searching the Web using a second server; i.e., the ASP
    server XMLHTTPs to a second server which is performing the searches.
    USUALLY the second server responds in a fairly short time, but once in a
    while it will be quite a while. It is possible that the user will want to
    "bail out". Within the ASP server, I can abort the XMLHTTP session with the
    second server if I know that I am to do it. We have implemented some
    safeguards such as having the second server time out, and also having the
    ASP server monitor the situation but there is STILL the possibility that the
    user wants to terminate the "Please Wait" page.

    Larry

    "Dave Anderson" <> wrote in message
    news:%...
    > "Larry Woods" wrote:
    > >
    > > What would be the best way to set a Session variable for the
    > > browser? A popup window ( 0 x 0 )?

    >
    > I should clarify my comments. Although I outlined a possible solution, it

    is
    > not one I recommend. You would be best served by designing processes that

    do
    > not need to be interrupted, as this other technique could be far more
    > demanding on resources than you anticipate.
    >
    > What are you trying to accomplish, and why do you need to stop a process
    > once it is underway?
    >
    >
    > --
    > Dave Anderson
    >
    > Unsolicited commercial email will be read at a cost of $500 per message.

    Use
    > of this email address implies consent to these terms. Please do not

    contact
    > me directly or ask me to contact you directly for assistance. If your
    > question is worth asking, it's worth posting.
    >
    >
    Larry Woods, Aug 11, 2003
    #6
  7. Larry Woods

    Larry Woods Guest

    That is a good idea, Aaron, but this solution is "IE only" and even though I
    wish that I could depend on that this site is a public site so I can't
    assume IE. Any other suggestions?

    TIA,

    Larry

    "Aaron Bertrand - MVP" <> wrote in message
    news:...
    > Use a hidden frame.
    > http://www.aspfaq.com/2001
    > http://www.aspfaq.com/2281
    >
    >
    > "Larry Woods" <> wrote in message
    > news:...
    > > Thanks, Dave.
    > >
    > > What would be the best way to set a Session variable for the browser? A
    > > popup window ( 0 x 0 )?
    > >
    > > TIA,
    > >
    > > Larry
    > >
    > > "Dave Anderson" <> wrote in message
    > > news:...
    > > > "Larry Woods" wrote:
    > > > >
    > > > > I have a server page that has served an HTML page with a "Cancel"
    > > > > button on it, BUT this server page has not completed and is running
    > > > > a 15-30 second process before it completes. I want the browser user
    > > > > to be able to terminate the page before the server process has
    > > > > finished...
    > > > > ...Is there some way that I can "signal" the server to stop
    > > > > processing so that I can go to the "location.href" page; or is there
    > > > > some other way?
    > > >
    > > > You cannot directly cancel the request. The best you can do is have

    the
    > > ASP
    > > > process constantly monitor some independent entity (a session variable

    > or
    > > a
    > > > record in a DB, for example), continuing only if some prearranged

    > > condition
    > > > is met. The cancel request would still be independent of the original
    > > > request, but this should be possible in principle.
    > > >
    > > >
    > > > --
    > > > Dave Anderson
    > > >
    > > > Unsolicited commercial email will be read at a cost of $500 per

    message.
    > > Use
    > > > of this email address implies consent to these terms. Please do not

    > > contact
    > > > me directly or ask me to contact you directly for assistance. If your
    > > > question is worth asking, it's worth posting.
    > > >
    > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Larry Woods, Aug 11, 2003
    #7
  8. Larry Woods

    Larry Woods Guest

    I'll look into the Google suggestion.

    I want the user to terminate the page, but not the present session. In
    another response to my question I have explained my application. The delay
    is a possible looooong Web search by the server.

    TIA,

    Larry

    "Michael D. Kersey" <> wrote in message
    news:...
    > Larry Woods wrote:
    > >
    > > I have a server page that has served an HTML page with a "Cancel" button

    on
    > > it, BUT this server page has not completed and is running a 15-30 second
    > > process before it completes.

    >
    > Long-running processes are not good for web servers. You should write
    > this application a different way. See
    >

    http://www.google.com/groups?hl=en&lr=&ie=UTF-8&selm=#eae9UZoCHA.1612@TK2MSFTNGP09
    > for a better way.
    >
    > > I want the browser user to be able to
    > > terminate the page before the server process has finished.

    >
    > Educate the user about the browser's "Stop" button. Alternatively the
    > user can click on another URL, select a bookmark, or enter a new URL.
    > When the Stop button is pressed, the TCP connection is reset and the
    > connection closed between client browser and server. Any queued output
    > will be discarded by whichever party (client, server or proxy agent) is
    > holding it.
    >
    > Good Luck,
    > Michael D. Kersey
    Larry Woods, Aug 11, 2003
    #8
  9. Larry Woods

    Bob Barrows Guest

    Well, you can use xmlhttp to run a second server-side page that sets a
    session cancel variable to true can't you?

    Bob

    Larry Woods wrote:
    > The application is searching the Web using a second server; i.e., the
    > ASP server XMLHTTPs to a second server which is performing the
    > searches. USUALLY the second server responds in a fairly short time,
    > but once in a while it will be quite a while. It is possible that
    > the user will want to "bail out". Within the ASP server, I can abort
    > the XMLHTTP session with the second server if I know that I am to do
    > it. We have implemented some safeguards such as having the second
    > server time out, and also having the ASP server monitor the situation
    > but there is STILL the possibility that the user wants to terminate
    > the "Please Wait" page.
    >
    > Larry
    >
    > "Dave Anderson" <> wrote in message
    > news:%...
    >> "Larry Woods" wrote:
    >>>
    >>> What would be the best way to set a Session variable for the
    >>> browser? A popup window ( 0 x 0 )?

    >>
    >> I should clarify my comments. Although I outlined a possible
    >> solution, it is not one I recommend. You would be best served by
    >> designing processes that do not need to be interrupted, as this
    >> other technique could be far more demanding on resources than you
    >> anticipate.
    >>
    >> What are you trying to accomplish, and why do you need to stop a
    >> process once it is underway?
    >>
    >>
    >> --
    >> Dave Anderson
    >>
    >> Unsolicited commercial email will be read at a cost of $500 per
    >> message. Use of this email address implies consent to these terms.
    >> Please do not contact me directly or ask me to contact you directly
    >> for assistance. If your question is worth asking, it's worth posting.
    Bob Barrows, Aug 11, 2003
    #9
  10. > That is a good idea, Aaron, but this solution is "IE only"

    What? You can't use a hidden frame like this, in other browsers:

    <frameset rows="99%, 1%">
    <frame ...
    <frame ...
    </frameset>

    ???
    Aaron Bertrand - MVP, Aug 11, 2003
    #10
  11. > It is possible that the user will want to "bail out".

    And such a user would use the STOP button, why are you trying to invent your
    own methodology to replace it?
    Aaron Bertrand - MVP, Aug 11, 2003
    #11
  12. Larry Woods wrote:
    >
    > I'll look into the Google suggestion.
    >
    > I want the user to terminate the page, but not the present session.

    Clicking on the Stop button resets the HTTP connection; it does not
    affect the current session.

    > In another response to my question I have explained my application. The delay
    > is a possible looooong Web search by the server.

    Consider doing the XMLHTTP fetches in a background task or program and
    not by an ASP page if they require more than a few seconds of
    processing. Otherwise your own web server's memory and CPU will be tied
    up waiting.

    A periodic VBScript batch run or a VB program can do the XMLHTTP
    searches and won't bog down your web server. Users' experiences will be
    better since they are free to do other browsing while waiting for the
    XMLHTTP searches to complete: users could check results hours or days
    later. When your web server goes down, requests are not lost. When your
    database server goes down, once it is restarted requests will be
    requeued automatically (the user doesn't have to re-enter them). You
    would get a more reliable, better-performing system.

    You could also provide users with a mechanism for killing a search if
    that search takes too long or if a user changes his/her mind and decides
    the search results are not necessary. All that is possible with the
    suggestion that I made on Google, but most is not available to you
    otherwise.

    Good Luck,
    Michael D. Kersey
    Michael D. Kersey, Aug 11, 2003
    #12
  13. Larry Woods

    Larry Woods Guest

    Sorry, guys! Just going by the statement by the author at the beginning of
    the article on aspfaq. Didn't check any further. Figured he knew. Oooops!

    Larry

    "Aaron Bertrand - MVP" <> wrote in message
    news:...
    > > That is a good idea, Aaron, but this solution is "IE only"

    >
    > What? You can't use a hidden frame like this, in other browsers:
    >
    > <frameset rows="99%, 1%">
    > <frame ...
    > <frame ...
    > </frameset>
    >
    > ???
    >
    >
    Larry Woods, Aug 12, 2003
    #13
  14. Larry Woods wrote:
    > Michael,
    > Could you clarify one of your statements:
    > "Otherwise your own web server's memory and CPU will be tied up waiting."
    > Are you saying that an ASP site does not multi-thread?

    No. What I meant was that:
    - each thread that loads an XMLHTTP component waits for completion of
    that component's request,
    - that wait apparently can take many seconds, or can timeout, or can
    fail,
    - during that wait time, the resources (memory, CPU) used by that thread
    are tied up and are unavailable for processing other HTTP requests.

    ASP (indeed, HTTP, but that is a bigger story) is designed so that
    requests are received, processed quickly and responses returned. Waiting
    for *any* I/O process (file access, database access, an XMLHTTP request
    to another website) ties up resources (CPU and memory). However, while
    file access and database access are typically performed in micro- or
    milli-seconds, an HTTP request is measured in seconds or tens of
    seconds. And the likelihood of timeout or failure is much, much higher
    for an HTTP request to a remote server than for a database or file
    access on a local server.

    Summary: long-running ASP scripts can bog down a web server if many
    requests arrive in a short time.

    Good Luck,
    Michael D. Kersey
    Michael D. Kersey, Aug 12, 2003
    #14
  15. The ASP page can see if the client is still active by
    checking Response.IsClientConnected (I think it is a
    memebr of Response, check the docs for more details) and
    if the client is not connected then stop processing the
    page.

    Alternatively you could try something detaild here;

    http://www.aspfree.com/articles/1333,1/articles.aspx

    Which is bascially Micahel's suggesting with code.

    ASP is mutli-threaded but you don't get too many threads,
    and the reason is that pages are supposed to execute very
    quickly. When you have long-running tasks then those
    threads can quickly get used up.

    >-----Original Message-----
    >I have a server page that has served an HTML page with

    a "Cancel" button on
    >it, BUT this server page has not completed and is running

    a 15-30 second
    >process before it completes. I want the browser user to

    be able to
    >terminate the page before the server process has

    finished. What I tried was
    >an onClick event that issued a "location.href..." in

    hopes that this would
    >load this referenced page, etc. but I have found that the

    browser waits
    >until the server process had compled before executing

    the "location.href".
    >Is there some way that I can "signal" the server to stop

    processing so that
    >I can go to the "location.href" page; or is there some

    other way?
    >
    >TIA,
    >
    >Larry Woods
    >
    >
    >.
    >
    Adrian Forbes - MVP, Aug 12, 2003
    #15
  16. Larry Woods

    Larry Woods Guest

    Great info, Adrian..and article, also.

    What determines the number of threads that ASP gets?

    Larry
    "Adrian Forbes - MVP" <> wrote in message
    news:0d1d01c360ae$6b6d5850$...
    > The ASP page can see if the client is still active by
    > checking Response.IsClientConnected (I think it is a
    > memebr of Response, check the docs for more details) and
    > if the client is not connected then stop processing the
    > page.
    >
    > Alternatively you could try something detaild here;
    >
    > http://www.aspfree.com/articles/1333,1/articles.aspx
    >
    > Which is bascially Micahel's suggesting with code.
    >
    > ASP is mutli-threaded but you don't get too many threads,
    > and the reason is that pages are supposed to execute very
    > quickly. When you have long-running tasks then those
    > threads can quickly get used up.
    >
    > >-----Original Message-----
    > >I have a server page that has served an HTML page with

    > a "Cancel" button on
    > >it, BUT this server page has not completed and is running

    > a 15-30 second
    > >process before it completes. I want the browser user to

    > be able to
    > >terminate the page before the server process has

    > finished. What I tried was
    > >an onClick event that issued a "location.href..." in

    > hopes that this would
    > >load this referenced page, etc. but I have found that the

    > browser waits
    > >until the server process had compled before executing

    > the "location.href".
    > >Is there some way that I can "signal" the server to stop

    > processing so that
    > >I can go to the "location.href" page; or is there some

    > other way?
    > >
    > >TIA,
    > >
    > >Larry Woods
    > >
    > >
    > >.
    > >
    Larry Woods, Aug 12, 2003
    #16
  17. Adrian Forbes - MVP, Aug 12, 2003
    #17
  18. Larry Woods

    Larry Woods Guest

    Ignorance on my part...

    I am instantiating a dll (visual basic-based) that is doing a bunch of
    calculations. I have not defined it within a transaction, or anything like
    that. It don't access any of the ASP objects, etc. The exposes some
    properties and methods. The user "feeds" some data via properties; then
    executes a method, which does the calculations, returning a value.

    Question: Is this running under MTS/COM+ ??

    TIA,

    Larry Woods

    "Adrian Forbes - MVP" <> wrote in message
    news:01c101c360e8$231c4400$...
    > >What determines the number of threads that ASP gets?

    >
    > IIS5 defaults to 25/processor and IIS4 10/processor but
    > you can change the defaults if you want.
    >
    > http://msdn.microsoft.com/library/default.asp?
    > url=/library/en-us/dnserv/html/server02282000.asp
    >
    > http://www.microsoft.com/serviceproviders/whitepapers/tunin
    > giis.asp
    >
    > More worrying that IIS's thread pool is if your long-
    > running code is inside MTS/COM+ as that has even less
    > threads given to it.
    >
    >
    Larry Woods, Aug 13, 2003
    #18
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tiewknvc9
    Replies:
    12
    Views:
    1,259
    Chris Uppal
    Feb 19, 2007
  2. Nathan Sokalski
    Replies:
    4
    Views:
    6,929
    Nathan Sokalski
    Jul 8, 2008
  3. Terry Reedy
    Replies:
    4
    Views:
    268
  4. Chris Angelico
    Replies:
    2
    Views:
    267
    Antoon Pardon
    Sep 21, 2011
  5. Stefan Mueller
    Replies:
    4
    Views:
    279
    Stefan Mueller
    Nov 5, 2005
Loading...

Share This Page