Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6836579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:22:20+00:00 2026-05-26T23:22:20+00:00

All, I have a ~/temp dir on my web root in the web server.

  • 0

All,
I have a ~/temp dir on my web root in the web server. Let’s say:
C:\inetpub\myapp\temp

and I have a method in the code behind class of a page that deletes all the files there. Everything works well.

protected CleanTemp() {
    // clean all the files in tmp dir
    Array.Foreach...
}

The problems is that if I create a timer in my Global.aspx that tries to execute such clean in the same way, the system lists the files in the temp dir but for each of them it returns an exception saying the user does not have the proper access rights:

[Global.aspx]

void Application_Start(object sender, EventArgs e) {
    PhisicalTmpFolder = Server.MapPath(~/temp);

    // create new timer
    System.Timers.Timer timScheduledTask = new System.Timers.Timer();
    timScheduledTask.Interval = 20 * 60 * 1000.0;
    timScheduledTask.Enabled = true;
    timScheduledTask.Elapsed += new System.Timers.ElapsedEventHandler(timScheduledTask_Elapsed);
}


void timScheduledTask_Elapsed(object sender, System.Timers.ElapsedEventArgs e) {
    // clean all the files in tmp dir
    Array.ForEach(
            Directory.GetFiles(PhisicalTmpFolder),
            delegate(string path) {
                try {
                    File.Delete(path); i++;
                } catch (Exception ex) {
                    if (_logger != null) _logger.Error(ex.Message, ex);
                }
            }
        );
}

How can I tell to the timer that it must run with the same access right of the application?

Thank you in advance,
Gianpiero

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:22:21+00:00Added an answer on May 26, 2026 at 11:22 pm

    I think the problem you have here is that the ASP.NET process account does not have the appropriate rights and you have user impersonation enabled so when the operation is initiated during a page request it is done so under the request user account which does have rights.

    Try granting the ASP.NET process account rights to that directory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

lets's say I have: // all objects have valid mapping to database public class
I have been wondering about temp tables in sp's and how all that can
I'm writing a bit of code for a class, but since I have no
Here's something I don't understand. In perl, let's say I have a file(handle) $file
i have this: Dim split As String() = temp_string.Split(,) ''#feed all info into global
I have three classes that all have a static function called 'create'. I would
I'm sure we all have received the wonderfully vague Object reference not set to
I have created a bunch of movie clips which all have similar names and
I have a bunch of projects in parallel subdirectories that all have etc/lighttpd.conf files.
I have a MFC dialog with 32 CComboBoxes on it that all have the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.