Session_OnEnd does not DeleteFile()

Discussion in 'ASP General' started by andrea azzini, Feb 26, 2005.

  1. I've got an ASP3 (IIS6) site, in which some scripts need to generate
    temporary files in order to work. Now, the fact is: I would like those
    temporary files to be deleted when a user's session ends (even though i've
    got infinite hosting space, i feel it somewhat impolite to leave GB's of
    useless temp files ;-) ).

    The Session_OnEnd event, though, seems to have some problems in doing this:

    1. I found in MSDN that it couldn't call Server.MapPath(). Not a big
    problem, I hardcoded the base path and everything should have worked well.
    2. The FileSystemObject.DeleteFile() method, though, seems to suffer from
    the same problem: i get no error output on Session.Abandon() but the files
    are still there.

    Is there any workaround for this problem?
    Thanks in advance
    Andrea Azzini
     
    andrea azzini, Feb 26, 2005
    #1
    1. Advertising

  2. andrea azzini wrote:
    > I've got an ASP3 (IIS6) site, in which some scripts need to generate
    > temporary files in order to work. Now, the fact is: I would like those
    > temporary files to be deleted when a user's session ends (even though
    > i've got infinite hosting space, i feel it somewhat impolite to leave
    > GB's of useless temp files ;-) ).
    >
    > The Session_OnEnd event, though, seems to have some problems in doing
    > this:
    >
    > 1. I found in MSDN that it couldn't call Server.MapPath(). Not a big
    > problem, I hardcoded the base path and everything should have worked
    > well.
    > 2. The FileSystemObject.DeleteFile() method, though, seems to suffer
    > from the same problem: i get no error output on Session.Abandon() but
    > the files are still there.
    >
    > Is there any workaround for this problem?
    > Thanks in advance
    > Andrea Azzini


    Your IWAM_machinename account needs Change permissions for the folder.
    Bob Barrows

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Feb 26, 2005
    #2
    1. Advertising

  3. ehp... not possible... i mean, have an hosting plan so i can't access the
    server's system settings. But ASP scripts have full access permissions to
    that specific folder.


    "Bob Barrows [MVP]" <> ha scritto nel messaggio
    news:%...
    > andrea azzini wrote:
    > > I've got an ASP3 (IIS6) site, in which some scripts need to generate
    > > temporary files in order to work. Now, the fact is: I would like those
    > > temporary files to be deleted when a user's session ends (even though
    > > i've got infinite hosting space, i feel it somewhat impolite to leave
    > > GB's of useless temp files ;-) ).
    > >
    > > The Session_OnEnd event, though, seems to have some problems in doing
    > > this:
    > >
    > > 1. I found in MSDN that it couldn't call Server.MapPath(). Not a big
    > > problem, I hardcoded the base path and everything should have worked
    > > well.
    > > 2. The FileSystemObject.DeleteFile() method, though, seems to suffer
    > > from the same problem: i get no error output on Session.Abandon() but
    > > the files are still there.
    > >
    > > Is there any workaround for this problem?
    > > Thanks in advance
    > > Andrea Azzini

    >
    > Your IWAM_machinename account needs Change permissions for the folder.
    > Bob Barrows
    >
    > --
    > Microsoft MVP -- ASP/ASP.NET
    > Please reply to the newsgroup. The email account listed in my From
    > header is my spam trap, so I don't check it very often. You will get a
    > quicker response by posting to the newsgroup.
    >
    >
     
    andrea azzini, Feb 26, 2005
    #3
  4. Session and Application events run under the IWAM account, not the IUSR.
    There is no other solution. IWAM needs file-system permissions for that
    folder.

    Bob Barrows
    andrea azzini wrote:
    > ehp... not possible... i mean, have an hosting plan so i can't access
    > the server's system settings. But ASP scripts have full access
    > permissions to that specific folder.
    >
    >
    > "Bob Barrows [MVP]" <> ha scritto nel
    > messaggio news:%...
    >> andrea azzini wrote:
    >>> I've got an ASP3 (IIS6) site, in which some scripts need to generate
    >>> temporary files in order to work. Now, the fact is: I would like
    >>> those temporary files to be deleted when a user's session ends
    >>> (even though i've got infinite hosting space, i feel it somewhat
    >>> impolite to leave GB's of useless temp files ;-) ).
    >>>
    >>> The Session_OnEnd event, though, seems to have some problems in
    >>> doing this:
    >>>
    >>> 1. I found in MSDN that it couldn't call Server.MapPath(). Not a big
    >>> problem, I hardcoded the base path and everything should have worked
    >>> well.
    >>> 2. The FileSystemObject.DeleteFile() method, though, seems to suffer
    >>> from the same problem: i get no error output on Session.Abandon()
    >>> but the files are still there.
    >>>
    >>> Is there any workaround for this problem?
    >>> Thanks in advance
    >>> Andrea Azzini

    >>
    >> Your IWAM_machinename account needs Change permissions for the
    >> folder. Bob Barrows
    >>
    >> --
    >> Microsoft MVP -- ASP/ASP.NET
    >> Please reply to the newsgroup. The email account listed in my From
    >> header is my spam trap, so I don't check it very often. You will get
    >> a quicker response by posting to the newsgroup.


    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Feb 26, 2005
    #4
  5. No way to get that. But I've found another solution... i'll use a BLOB in
    the mysql database where i surely have all the access rights i need. Thanx
    anyway.

    "Bob Barrows [MVP]" <> ha scritto nel messaggio
    news:%...
    > Session and Application events run under the IWAM account, not the IUSR.
    > There is no other solution. IWAM needs file-system permissions for that
    > folder.
    >
    > Bob Barrows
    > andrea azzini wrote:
    > > ehp... not possible... i mean, have an hosting plan so i can't access
    > > the server's system settings. But ASP scripts have full access
    > > permissions to that specific folder.
    > >
    > >
    > > "Bob Barrows [MVP]" <> ha scritto nel
    > > messaggio news:%...
    > >> andrea azzini wrote:
    > >>> I've got an ASP3 (IIS6) site, in which some scripts need to generate
    > >>> temporary files in order to work. Now, the fact is: I would like
    > >>> those temporary files to be deleted when a user's session ends
    > >>> (even though i've got infinite hosting space, i feel it somewhat
    > >>> impolite to leave GB's of useless temp files ;-) ).
    > >>>
    > >>> The Session_OnEnd event, though, seems to have some problems in
    > >>> doing this:
    > >>>
    > >>> 1. I found in MSDN that it couldn't call Server.MapPath(). Not a big
    > >>> problem, I hardcoded the base path and everything should have worked
    > >>> well.
    > >>> 2. The FileSystemObject.DeleteFile() method, though, seems to suffer
    > >>> from the same problem: i get no error output on Session.Abandon()
    > >>> but the files are still there.
    > >>>
    > >>> Is there any workaround for this problem?
    > >>> Thanks in advance
    > >>> Andrea Azzini
    > >>
    > >> Your IWAM_machinename account needs Change permissions for the
    > >> folder. Bob Barrows
    > >>
    > >> --
    > >> Microsoft MVP -- ASP/ASP.NET
    > >> Please reply to the newsgroup. The email account listed in my From
    > >> header is my spam trap, so I don't check it very often. You will get
    > >> a quicker response by posting to the newsgroup.

    >
    > --
    > Microsoft MVP -- ASP/ASP.NET
    > Please reply to the newsgroup. The email account listed in my From
    > header is my spam trap, so I don't check it very often. You will get a
    > quicker response by posting to the newsgroup.
    >
    >
     
    andrea azzini, Feb 26, 2005
    #5
  6. I'll echo what Bob said.
    See http://www.aspfaq.com/2078


    On 2/26/05 12:38 PM, in article Ju2Ud.52792$,
    "andrea azzini" <> wrote:

    > I've got an ASP3 (IIS6) site, in which some scripts need to generate
    > temporary files in order to work. Now, the fact is: I would like those
    > temporary files to be deleted when a user's session ends (even though i've
    > got infinite hosting space, i feel it somewhat impolite to leave GB's of
    > useless temp files ;-) ).
    >
    > The Session_OnEnd event, though, seems to have some problems in doing this:
    >
    > 1. I found in MSDN that it couldn't call Server.MapPath(). Not a big
    > problem, I hardcoded the base path and everything should have worked well.
    > 2. The FileSystemObject.DeleteFile() method, though, seems to suffer from
    > the same problem: i get no error output on Session.Abandon() but the files
    > are still there.
    >
    > Is there any workaround for this problem?
    > Thanks in advance
    > Andrea Azzini
    >
    >
     
    Aaron [SQL Server MVP], Feb 27, 2005
    #6
  7. andrea azzini

    Roland Hall Guest

    "andrea azzini" <> wrote in message
    news:XA7Ud.52831$...
    : No way to get that. But I've found another solution... i'll use a BLOB in
    : the mysql database where i surely have all the access rights i need. Thanx
    : anyway.

    Can you say performance hit? I chose a different path for cleanup. I wrote
    a routine the merchant runs once a day. It cleans up all temp files 3 days
    or older, or whatever their retention setting is.

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
     
    Roland Hall, Feb 27, 2005
    #7
  8. This sounds really interesting, i had not thought about it... but, is there
    any way to have a script run at an aribitrary time or should i just put it
    into another (frequently accessed) page and let it check whether it's time
    to run or not?
    Remember i am on hosting so i can't do more than edit the files in my site's
    directory...


    "Roland Hall" <nobody@nowhere> ha scritto nel messaggio
    news:%...
    > "andrea azzini" <> wrote in message
    > news:XA7Ud.52831$...
    > : No way to get that. But I've found another solution... i'll use a BLOB

    in
    > : the mysql database where i surely have all the access rights i need.

    Thanx
    > : anyway.
    >
    > Can you say performance hit? I chose a different path for cleanup. I

    wrote
    > a routine the merchant runs once a day. It cleans up all temp files 3

    days
    > or older, or whatever their retention setting is.
    >
    > --
    > Roland Hall
    > /* This information is distributed in the hope that it will be useful, but
    > without any warranty; without even the implied warranty of merchantability
    > or fitness for a particular purpose. */
    > Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    > WSH 5.6 Documentation -

    http://msdn.microsoft.com/downloads/list/webdev.asp
    > MSDN Library - http://msdn.microsoft.com/library/default.asp
    >
    >
     
    andrea azzini, Feb 27, 2005
    #8
  9. This also clarifies some question i had wondered about the difference
    between those two users on my testing server... thank you.


    "Aaron [SQL Server MVP]" <> ha scritto nel messaggio
    news:BE46A924.1557%...
    > I'll echo what Bob said.
    > See http://www.aspfaq.com/2078
    >
    >
    > On 2/26/05 12:38 PM, in article Ju2Ud.52792$,
    > "andrea azzini" <> wrote:
    >
    > > I've got an ASP3 (IIS6) site, in which some scripts need to generate
    > > temporary files in order to work. Now, the fact is: I would like those
    > > temporary files to be deleted when a user's session ends (even though

    i've
    > > got infinite hosting space, i feel it somewhat impolite to leave GB's of
    > > useless temp files ;-) ).
    > >
    > > The Session_OnEnd event, though, seems to have some problems in doing

    this:
    > >
    > > 1. I found in MSDN that it couldn't call Server.MapPath(). Not a big
    > > problem, I hardcoded the base path and everything should have worked

    well.
    > > 2. The FileSystemObject.DeleteFile() method, though, seems to suffer

    from
    > > the same problem: i get no error output on Session.Abandon() but the

    files
    > > are still there.
    > >
    > > Is there any workaround for this problem?
    > > Thanks in advance
    > > Andrea Azzini
    > >
    > >

    >
     
    andrea azzini, Feb 27, 2005
    #9
  10. > This sounds really interesting, i had not thought about it... but, is there
    > any way to have a script run at an aribitrary time or should i just put it
    > into another (frequently accessed) page and let it check whether it's time
    > to run or not?


    I think there are web-based cron-type services out there that will allow you
    to schedule hits against your URLs from their remote servers. You can also
    see http://www.aspfaq.com/2143
     
    Aaron [SQL Server MVP], Feb 27, 2005
    #10
  11. andrea azzini

    Roland Hall Guest

    "andrea azzini" wrote in message
    news:vblUd.53852$...
    : This sounds really interesting, i had not thought about it... but, is
    there
    : any way to have a script run at an aribitrary time or should i just put it
    : into another (frequently accessed) page and let it check whether it's time
    : to run or not?
    : Remember i am on hosting so i can't do more than edit the files in my
    site's
    : directory...

    I didn't look at Aaron's link but if you cannot get it scheduled, I looked
    at it this way. My customer has a menu for administration. This is
    separate than maintenance. Administration has two functions.

    1. Get orders
    2. Cleanup

    Get orders will show a list of all order files and they can be viewed,
    printed and archived.
    Cleanup cleans up all temporary files in the orders file directory that are
    3 days or older, based on a value in the config file.
    I inform them to run a cleanup at least once when getting orders. My
    shopping cart cleans up files when orders are complete and only leaves
    successful order files. I cannot determine if someone fails to complete a
    shopping experience but I can try to do cleanup with Session_OnEnd. I found
    several issues with that approach. So, I chose to just make a generic
    routine that cleans up the files. There are 2 files left if the order is
    not completed for each shopper. 50 shoppers = 100 files. They are single
    digit k byte XML files. 100 files would be less than 1mb. This is only for
    unprocessed orders and they are only created if someone leaves something in
    their shopping cart and either leaves the site, closes their browser or
    times out.

    I also didn't want to clean them automatically in case someone was having
    trouble and called support. This would give the support person something to
    look at so the order could be completed on the phone.

    For those who host their own sites, I can offer an automated cleanup, if
    desired. Nobody yet has requested this process be automatic since cleanup
    takes care of it and only takes seconds at the most.

    HTH...

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
     
    Roland Hall, Feb 28, 2005
    #11
  12. andrea azzini

    Propin Guest

    Have the same problem, IWAM_machinename did not solve my problem. Have
    created the following test code (file is never deleted on my IIS6 Win2003
    environment, any idea?):

    <SCRIPT LANGUAGE="VBScript" RUNAT="Server">

    Sub Application_OnStart

    End Sub

    Sub Session_OnStart

    Set objFileSystemObject = Server.CreateObject("Scripting.FilesystemObject")


    objFileSystemObject.CreateTextFile "C:\temp\error\Test.txt", True

    Set objFileSystemObject = Nothing


    End Sub

    Sub Session_OnEnd


    Set objFileSystemObject = Server.CreateObject("Scripting.FilesystemObject")


    objFileSystemObject.CreateTextFile "C:\temp\error\Test.txt", True

    Set objFileSystemObject = Nothing

    End Sub

    Sub Application_OnEnd

    End Sub

    </SCRIPT>

    /Propin





    "Bob Barrows [MVP]" <> wrote in message
    news:%...
    > andrea azzini wrote:
    >> I've got an ASP3 (IIS6) site, in which some scripts need to generate
    >> temporary files in order to work. Now, the fact is: I would like those
    >> temporary files to be deleted when a user's session ends (even though
    >> i've got infinite hosting space, i feel it somewhat impolite to leave
    >> GB's of useless temp files ;-) ).
    >>
    >> The Session_OnEnd event, though, seems to have some problems in doing
    >> this:
    >>
    >> 1. I found in MSDN that it couldn't call Server.MapPath(). Not a big
    >> problem, I hardcoded the base path and everything should have worked
    >> well.
    >> 2. The FileSystemObject.DeleteFile() method, though, seems to suffer
    >> from the same problem: i get no error output on Session.Abandon() but
    >> the files are still there.
    >>
    >> Is there any workaround for this problem?
    >> Thanks in advance
    >> Andrea Azzini

    >
    > Your IWAM_machinename account needs Change permissions for the folder.
    > Bob Barrows
    >
    > --
    > Microsoft MVP -- ASP/ASP.NET
    > Please reply to the newsgroup. The email account listed in my From
    > header is my spam trap, so I don't check it very often. You will get a
    > quicker response by posting to the newsgroup.
    >
    >
     
    Propin, Apr 26, 2005
    #12
    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. anand

    my session_onend is not working

    anand, Jul 9, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    1,387
  2. Raghu Raman

    Urgent help pls.Session_onend does'nt fire

    Raghu Raman, May 5, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    386
    Raghu Raman
    May 6, 2005
  3. rbt
    Replies:
    4
    Views:
    2,190
  4. Julia B
    Replies:
    7
    Views:
    1,062
    Ed Murphy
    Aug 25, 2009
  5. Tom Bates

    DeleteFile doesn't work in Session_OnEnd???

    Tom Bates, Sep 7, 2003, in forum: ASP General
    Replies:
    3
    Views:
    134
    Tom Bates
    Sep 7, 2003
Loading...

Share This Page