Archive for May, 2011

There is often a need to determine which application pool a w3wp.exe process is responsible for. There are separate commands for determining this in depending on the version of IIS.

IIS 6:
When running IIS 6 the following command can be used in a command prompt:

iisapp

Example output:

This process ID will match what is displayed on the Task Manager.

IIS 7:
The iisapp command will not work on IIS 7 however Microsoft provides an equivalent command:


%windir%\system32\inetsrv\appcmd.exe list wp

Example output:

This article assumes you have already installed the HTTP Redirection role. If this has not been installed follow the instructions listed here first:
Install HTTP Redirection in IIS 7

*Note: IIS creates a new web.config file or edits an existing one when a redirect is added. To avoid causing issues with an existing web.config file it is recommended to create a new site in IIS specifically for the redirect. Then the home directory for this new site can be pointed to an empty folder.

1. Open IIS and select the desired site.

2. Double click “HTTP Redirect” under the “IIS” heading.

3. Check the box next to “Redirect requests to this destination:” and enter the desired URL to redirect to.

4. Check the box next to “Redirect all requests to exact destination”

5. Choose the desired status code for the redirect. Most users choose the “Permanent (301)” as it will tell browsers the location has permanently changed. If this is something temporary like a maintenance page, select either of the other two options instead.

6. Click “Apply” under the Actions heading on the right hand side and test the new redirect.

Unfortunately the Exchange Management Console does not allow use of wildcard values for things like senders and recipients. These need to be specific user or list of users. However you can search these logs for wildcard values using the Exchange Management Shell.

Here are two examples to search for any user at example.com. These will output the results to a text file for easier viewing. Make sure to update the date ranges and domain name as needed.

Search for messages sent TO any users at example.com:

Get-MessageTrackingLog -ResultSize Unlimited -Start "5/1/2011" -End "5/12/2011" | where{$_.recipients -like "*@example.com"} | select-object Timestamp,SourceContext,Source,EventId,MessageSubject,Sender,{$_.Recipients} | export-csv C:\ExchangeLogResults.txt

Search for messages sent FROM users at example.com:

Get-MessageTrackingLog -ResultSize Unlimited -Start "5/1/2011" -End "5/12/2011" | where{$_.sender -like "*@example.com"} | select-object Timestamp,SourceContext,Source,EventId,MessageSubject,Sender,{$_.Recipients} | export-csv C:\ExchangeLogResults.txt

This information applies to Exchange 2003, 2007, and 2010.

I needed a way to be notified by email when a SQL failover occurred. The simple solution for this is to setup a job to send an email and set this job to be triggered when SQL agent starts. The SQL agent service on the passive server starts when a failover occurs.

The instructions are for SQL Server 2008 but the steps should be similar in other versions.

First we need to setup a SQL mail profile to connect to a mail server. This mail service does not need to be installed on the same server as SQL. If this is already configured skip to the “Configure the SQL job” section below.

Setup SQL mail profile:
1. Open Management Studio, connect to your SQL cluster, and expand Management

2. Double click Database Mail to start the Mail Configuration Wizard

3. Select Set up Database Mail by performing the following tasks -> Next

4. Enter a relevant profile name then hit Add next to SMTP accounts

5. Enter the email address you want to use for these alerts. I highly recommend using an existing user and enabling basic authentication. Otherwise you may have to allow the SQL server to send through your mail server without authentication.

6. Click Next -> Next -> Next -> Finish

Configure the SQL job:
1. Expand SQL Server Agent

2. Right click Jobs -> New Job

3. Fill out the General page with relevant details then click the Steps page -> New

4. Enter an appropriate name for the step and set type to Transact-SQL script (T-SQL)

5. Enter the following in the Command field. Make sure to modify the values as needed.


EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'My mail account name',
@recipients='alerts@mydomain.com',
@Body='SQL Agent has started on the passive server.',
@from_address= 'alerts@mydomain.com',
@subject='SQL Cluster Failover Alert';

6. Click OK

7. Click the Schedules page -> New

8. Name the schedule appropriately and set schedule type to “Start automatically when SQL Server Agent starts”

9. Click OK -> OK

10. Right click the new job and select “Start job at step” to test the new job and make sure it can send mail properly

It is possible to restrict access to a specific site in IIS 7 by IP address or domain. This article will cover installing the necessary role and adding allow/deny rules.

First the “IP and Domain Restrictions” Role will need to be installed:

1. Click Start -> Administrative Tools -> Server Manager

2. Expand Roles -> Add Role Services under Web Server (IIS)

3. Check the box next to IP and Domain Restrictions under the Security heading

4. Click Next -> Install

Now the restrictions can be setup through IIS:
1. Open IIS and select the site you wish to restrict

2. Under the Features View click IP Address and Domain Restrictions

3. Click Add Allow Entry and enter the IP or range you want to allow access from

4. In order to deny all other addresses click Edit Feature Settings under Actions

5. Set Access for unspecified clients to Deny -> OK