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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:09:20+00:00 2026-06-07T14:09:20+00:00

I want to retrieve some performance counters for the ‘ASP.NET Applications’ category from within

  • 0

I want to retrieve some performance counters for the ‘ASP.NET Applications’ category from within my ASP.NET application.

My problem is, that I don’t know how to determine the correct instance name for my current running ASP.NET application.

I currently use this code:

string instanceName = GetCurrentProcessInstanceName();

_perfCounters.Add(new PerformanceCounter("ASP.NET", "Application Restarts"));
_perfCounters.Add(new PerformanceCounter("ASP.NET Applications", "Pipeline Instance Count", instanceName));
_perfCounters.Add(new PerformanceCounter("ASP.NET Applications", "Requests Executing", instanceName));
_perfCounters.Add(new PerformanceCounter("ASP.NET Applications", "Requests/Sec", instanceName));
_perfCounters.Add(new PerformanceCounter("ASP.NET Applications", "Requests Failed", instanceName));

For GetCurrentProcessInstanceName I defined those helper methods from information and code snippets I found on the intertubes:

    private static string GetCurrentProcessInstanceName()
    {
        return GetProcessInstanceName(GetCurrentProcessId());
    }

    private static int GetCurrentProcessId()
    {
        return Process.GetCurrentProcess().Id;
    }

    private static string GetProcessInstanceName(int pid)
    {
        PerformanceCounterCategory cat = new PerformanceCounterCategory("Process");

        string[] instances = cat.GetInstanceNames();
        foreach (string instance in instances)
        {

            using (PerformanceCounter cnt = new PerformanceCounter("Process", "ID Process", instance, true))
            {
                int val = (int) cnt.RawValue;
                if (val == pid)
                {
                    return instance;
                }
            }
        }

        return null;
    }

Now the problem is, that I get the following error:
Instance ‘w3wp’ does not exist in the specified Category.

So obviously, the code snippets don’t return the correct instance ID for the current application.

My question is: How can I determine (reliable) the correct value?

Additional information:
Since I learned that one should initially create a performance counter object and re-use this instance (vs. creating this object on every occasion you need this) I fire up a singleton when the application starts up. Out of this reason, I don’t have access to a current HttpRequest, since this happens before a request hits the application.

  • 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-06-07T14:09:22+00:00Added an answer on June 7, 2026 at 2:09 pm

    I found the solution, and it’s quite simpel:

    string curentWebApplicationInstanceName = System.Web.Hosting.HostingEnvironment.ApplicationID.Replace('/', '_');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using mysql and facing some problem. I want to retrieve last row
I want to serialize some information I retrieve from the user in a small
I want to start several threads, retrive data from net, perform some actions with
I want to retrieve some values from my url and post them in a
I have a simple MVC3 application that I want to retrieve some configuration details
I want to use java.net.url to crawl some websites and retrieve some data. I
I want to retrieve some data items from a web page. Link of webpage:
i want to retrieve some data from this website: http://sites.target.com/site/en/spot/search_results.jsp?&mapType=enhanced&startAddress=72756&startingLat=36.322757720947266&startingLong=-93.99922943115234&_requestid=2573952 There are following lines
I have Gridview and I want to retrieve some Information from data base(SQL). and
I have created a database and i want to retrieve some data from 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.