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 379185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:52:02+00:00 2026-05-12T14:52:02+00:00

I want to Recycle IIS 6’s App Pool in a web app using asp.net

  • 0

I want to Recycle IIS 6’s App Pool in a web app using asp.net c#.

protected void Page_Load(object sender, EventArgs e)
{
    //Recycle IIS 6's App Pool
    Recycle("localhost", "appPool_02");

}

void Recycle(string machine, string appPoolName)
{
    string path = "IIS://" + machine + "/W3SVC/AppPools/" + appPoolName;
    DirectoryEntry w3svc = new DirectoryEntry(path);
    w3svc.Invoke("Recycle", null);
}

“appPool_02” is another app pool name, and the above code is running on “appPool_01”.

When I used the code above, it occured an error:

拒绝访问。 (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: 拒绝访问。 (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET access to a file, right-click the file in Explorer, choose “Properties” and select the Security tab. Click “Add” to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

Source Error:

Line 72:         string path = "IIS://" + machine + "/W3SVC/AppPools/" + appPoolName;
Line 73:         DirectoryEntry w3svc = new DirectoryEntry(path);
Line 74:         w3svc.Invoke("Recycle", null);
Line 75:     }
Line 76: 

Source File: e:\iProject\iProgress\iProgress\T\T.aspx.cs Line: 74

Stack Trace:

[UnauthorizedAccessException: 拒绝访问。 (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))]

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.DirectoryServices.DirectoryEntry.Invoke(String methodName, Object[] args) +238
WE_T.Recycle(String machine, String appPoolName) in e:\iProject\iProgress\iProgress\T\T.aspx.cs:74
WE_T.Page_Load(Object sender, EventArgs e) in e:\iProject\iProgress\iProgress\T\T.aspx.cs:38
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

  • 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-12T14:52:02+00:00Added an answer on May 12, 2026 at 2:52 pm

    I got it working by setting the AppPool as working as “Local System”. But this may cause some security issue. Is there any better solution?

    Text to Speech in ASP.NET – Access is denied… what to do?

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

Sidebar

Related Questions

I want a ASP.NET cache item to be recycled when a specific file is
I'm currently convering my ASP.NET v2 application to serialize/deserialize it's objects because I want
A have ASP.NET 2.0 web application that should allow sending emails. I have a
I have a number of ASP.NET (4.0) web applications that appear to leak (a
I have an ASP .NET web application which on the backend is talking to
I want to cache custom data in an ASP.NET application. I am putting lots
Is it possible to recycle a WCF web service hosted on IIS from code?
I am experimenting with using subversion to deploy updates to my ASP.Net application, one
want to know why String behaves like value type while using ==. String s1
I want use many bitmap for my game canvas. I can't Recycle bitmaps, because

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.