Showing posts with label IIS. Show all posts
Showing posts with label IIS. Show all posts

Saturday, 25 April 2015

Performance Monitor (perfmon): Correlating w3wp# to App pool process


The Windows Performance Monitor (perfmon) is a useful tool to capture run-time performance metrics such as CPU utilisation, .NET  GC runs etc.

Problem

The IIS web applications execute on multiple"w3wp" processes and it can be difficult to profile a single web application using perfmon. Perfmon simply name each process as "w3wp#1", "w3wp#2", which is not helpful at all!.
Multiple w3wp processes in perfmon


The goal of this post is to help identify the relevant "w3wp" process and map it back to the application pool.

Step 1 : Find the Process Id of the application pool process

Navigate to C:\Windows\System32\inetsvr folder and issue the command in the following screen capture. (appcmd list wp).
Finding out Process Id per application pool

The appcmd command returns the names of each application pool together with their process Ids. At this point we know the process Id and application pool that we are interested in.

Step 2: Add the requisite performance metric to perfmon

Simply add the metric to perfmon. I have added the CPU utilisation and most importantly the process Id. The process Id can be found under "Process" category.
Adding CPU utilisation with process Id

Step 3: Monitor the metric added in Step 2 

The sample metric looks like below:

Captured metric in perfmon
The most interesting piece of information is highlighted in the capture. We can see that the process id "4780" is in fact the "Stub" service as per Step 1.

Concerns

What if there are dozens of web application in IIS? The steps discussed here are for a simple case and does not scale well unfortunately. However I have seen some answers in StackOverflow that suggest to modify few registry keys that can provide a more meaningful name.

I do see that perfmon is not the best tool for performance monitoring. But I do think it is not too bad once you get use to it. (I do prefer dotTrace!).

Tuesday, 16 April 2013

("quirky") SQL Server with IIS App Pool users

Scene

So you have developed a great .NET MVC web application. All the unit/integration tests passing and ready to go live!. You have tested the site using Visual Studio built-in web server (Cassini) and would like to try it out in "real" IIS.

New site is created and deployed but you are faced with the "yellow-screen-of-death".



The issue is that the site is impersonating the application pool user. As we just want to view the site, we can go to SQL Server and give the application pool user (IIS APPPOOL\SamplesSites) the permission to read the database. Simple!

Problem

We can add a new SQL Server user mapped to the IIS AppPool user. (See below.)


Looks good, but when we try to add a new user, we get the following error.


This is very strange. Even though the "Select User" dialog finds the application pool user, it cannot be mapped to a SQL Server login.

Solution

Here comes the MAGIC!

If you return to the "Login - New" dialog and type in the application pool user and click "OK" then the login is added.



Once the user is added, you can see it by expanding the security tab. (See below).


Fun!

(see this post for more information.)

Sunday, 26 February 2012

Configuring IIS host header for a site with non-wild card SSL certificate

The "host name" is an important piece of configuration that must set when creating sites using IIS.

The “host name” can be set of a site in IIS v7.5 when a wild-card certificate (*.mysite.net) is used. See below:

Instead of a wild-card certificate, it is possible to obtain a certificate issued to a certain host name (env-live.mysite.net). At this point we do not have any other choice but set the host name for the site as “env-live.mysite.net” in IIS.

Now consider a scenario where a SSL certificate issued to “web-test-stage.domain.local” host name. It is possible that this certificate is installed in a server called “web-test-stage”. The IIS manager will not let you set the host name in this scenario. See below:


In the above screen capture, the SSL certificate is issued to “AcerUser-PC” which happens to be name of the computer. Once the site is created we can clearly see that the host name is not set.


The “TestSite” can now be accessed using the following methods:

  •  https://AcerUser-PC or
  •  https://IP Address of AcerUser computer 


Now, you might wonder is it worth worrying about this? I think this is something we should keep in mind.

The client accessing the web site must use the host name (I think). So, a user trying to access the site should not use the IP address. I think this make perfect sense in a case where multiple sites are hosted at the same IIS (IP address).

The way we can set the host name is through the command line. Open command prompt as an administrator and navigate to C:\Windows\System32\inetsrv folder.

Thereafter execute the following command. 

appcmd set site /site.name:TestSite /bindings.[protocol='https',bindingInformation='*:443:'].bindingInformation:*:443:AcerUser-PC


Return to IIS and refresh the site.


By selecting the “Edit Site Bindings” we can see that the host name header is set. But if we edit this property “host name” text box is disabled.

We must be very careful at this point. Do NOT click “OK” as it clears the host name.

I agree that the scenario I discussed here is pretty strange and you may never come across such a requirement. But we must keep in mind the best practises of IIS security which requires a host name for a site. 

To be honest, I am not very keen on implementing this in a production environment as it deviates from the standard IIS configuration (but its worth knowing...)