Archive

Posts Tagged ‘IIS’

URL Rewrite module for IIS7

August 16th, 2010 Rob Comments off

As part of a larger project I’ve been involved with which uses an IIS7 web application (I’ve been helping the client with their infrastructure and integrating the application with AD) we hit an issue where some 3rd party pieces of code were using absolute links *tut tut*! rather than relative ones, this had the side effect that a user would start off their session using an SSL secured https session & after performing certain tasks would find themselves on http.  Not ideal!  The application also has a requirement that the web servers are able to connect to themselves on port 80 – this could not be changed & interfering with this connection would break functionality.

To resolve this I’ve implemented the Microsoft URL Rewrite module 2 for IIS7, with the following configuration:

  1. Download and install the IIS URL re-writing module: http://www.iis.net/download/urlrewrite
  2. Go to the site in IIS manager & navigate to URL Rewrite in the right hand pain
  3. Create a new inbound rule with the following settings:
  4. Match URL:
    1. Requested URL: ‘Matches the pattern’
    2. Using: ‘Regular Expressions’
    3. Pattern: ‘(.*)’
    4. Ignore Case: ‘True’
  5. Conditions:
    1. Input ‘{HTTPS}’ Type ‘Matches the pattern’ Pattern ‘^OFF$’
    2. Input ‘{LOCAL_ADDR}’ Type ‘Does not match the pattern’ Pattern ‘127.0.0.1’
  6. Action: ‘Redirect’ Redirect URL: ‘https://{HTTP_HOST}/{R:1}’ Append Query String: True Redirect type: ‘See Other (303)’

This will not only correct broken URLs which get returned but will redirect users who hit the site via http to https which is a requirement for the service.

Handy fix – I’d often use TMG / ISA to resolve this but this customer’s solution does not feature those products (the site is being deployed internally).

 

Rob

Categories: Uncategorized Tags: ,

Redirect IIS Websites Homepage with IIS 7.0

January 7th, 2010 Daniel Davies Comments off

You may come across an issue from time to time.  Where you have an IIS website and when you type the URL of the IIS Site into your IE it brings up a homepage, but you would like to change the homepage for reason such as you would like to allow users to access a specific part of the site easier.

 For example

You have gave your IIS site a host header of “test” but you would like users to hit a different web page within the site when they simply type the host header in.

Currently they are hitting the below webpage when typing http://test

image

But this is not the page you want them to hit when they type in http://test we would like them to be redirected to http://test/test2 (Below Page)

image 

Resolution

To get this to work we will first have to create a htm file which redirects us to our desired site “http://test/test2

1, Open IIS Manager

2, Now expand the console until you get to your website and then switch to content view.

image

3, Right Click and press explore

image

4, Now we need to create the HTM in this location “C:Test”

5, Now open notepad and type the following in and put the url of what you want as your homepage and save it in the location we found out above and name it default.htm (Code Below was supplied by Rob http://risualblogs.com/blog/author/robb/)

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”>
<html>
<head>
<title></title>
<meta http-equiv=”REFRESH” content=”0;url=http://Type Your URl”></HEAD>
<BODY>
</BODY>
</HTML>

6, Now we need to make the “default.htm” the default document. So go back into the IIS Console  and switch back to Features View and double click Default Document.

image

7, Now simply press add and type in the name of the htm file and hit ok

image

8, The final thing we need to do is to move the default.htm file to the top of the default document list so it takes precedence. So simply click default.htm and press move up.

image

9, You will get a message pop up simply press yes as this is what we want to do

image

10, Now when you type in your host header URL (http://test ) you will get redirected to the correct page (http:testTest2).

Hope this Helps You :)

Categories: Uncategorized Tags: ,

IIS – How to tackle multiple web servers & keep them in sync

December 23rd, 2009 Rob Comments off

I’ve recently been engaged on a project where we have multiple web servers (IIS7.5 on 2008r2 for those interested) which require exactly the same content and configuration (they’re sitting behind a Forefront TMG server using a web farm).  The configuration in IIS for this application happens to be complicated & while I have documented how to configure the servers, doing it over and over will not only be tedious but probably introduce some human error. 

To resolve this issue I implemented IIS 7’s shared configuration and put a process in to replicate the content between web servers.

You will need a domain account (or local account on each web server if your web servers aren’t domain joined) which will be used to access the shared configuration (it only does this – your web applications continue to run under what ever application pool identity you have set) and a file share to store the configuration on.

Assuming you’re at the stage of having a configured web server with the IIS configuration how you want it you need to export the configuration:

  1. On the first web server / machine which will host the shared configuration create a directory & share it giving full share and ntfs permissions to the service account created, all other permissions should be removed.
  2. In IIS manager on the server with IIS configured as per the previous steps click on the server node in the left pane, then open shared configuration in the right pane, then finally select the export configuration option on the right, store the export in the directory created in step 1, entering an encryption key (this should be recorded as it is needed for all nodes which will be accessing the shared configuration).
  3. When exported tick the ‘Enable shared configuration’ box, enter the UNC path to the configuration (eg \machinenameiisconfig) enter the username domainserviceaccount and the password for that account, press apply, you will be prompted for the encryption key provided in step 2.
  4. Restart the server to apply configuration, then check IIS is still functioning and the IIS manager can be accessed.

The above steps will reconfigured your already configured web server to work from the shared configuration, now we need to replicate the web content and configure all other web servers to work from the same configuration.

There are several ways of replicating the physical content, DFSR is one option, however I chose not to use it as the content on the web servers is staying static so frequent updates to the other nodes will not be required and it gives the operator responsible for the servers more control over how content updates are deployed.  So instead I used robocopy (which has been built in since Vista / Server 2008) to mirror the content from the configured server to all others (this was executed on the web server to be copied to):

 

robocopy \configuredwebserverc$inetpubwwwroot c:inetpubwwwroot /MIR

 

Once the file content was in place two quick steps are required to configure IIS to use the shared configuration:

  1. Open IIS manager, click on the server name in the left pane, then select the shared configuration option in the right pane, tick the ‘Enable shared configuration’ box, enter the UNC path to the configuration as specified on the first web server (eg \machinenameiisconfig) enter the username domainserviceaccount and the password for that account, press apply, you will be prompted for the encryption key.
  2. Restart the server to apply configuration, then check IIS is still functioning and the IIS manager can be accessed.
    This process will replicate all application pools and IIS configuration, however if you have ODBC data sources etc.. (things external to IIS which your web applications are using) then you will need to find a way to replicate these settings as well. 
    An important point is how IIS behaves if the configuration becomes unavailable, under Server 2008 (not R2) if the configuration disappears IIS will essentially stop, under R2 the server will detect this, continue working and reconnect when the configuration source comes back online.  You can enable offline files for added resiliency should you require it.