IIS 7.5 and IIS 8.0 European Hosting

BLOG about IIS 7.5 Hosting, IIS 8.0 Hosting and Its Technology - Dedicated to European Windows Hosting Customer

IIS 8 Netherlands Hosting - HostForLIFE.eu :: Using Outbound Rewrite Rules to Offload Your Content on IIS 8

clock March 10, 2014 09:06 by author Peter

Recently a colleague of mine wrote an article on setting up a CDN (Content Delivery Network). This made me experiment a bit with some IIS 8 settings. It is possible to set up IIS to rewrite all outgoing requests in such a way that your static content (e.g. images, style-sheets, etc) will be downloaded from a separate location. The main benefit of this method is (in my opinion) that it doesn’t requiren any adjustments on your target site. All it requires is some tweaking of your web.config and ofcourse a working CDN.

Outbound rewrite rules are a pretty powerful thing, when used properly. When used incorrectly, they can slow your site down to a screeching halt. Lucky for us, the outbound rewrite rules can be used to filter out specific requests. In this case we will use them to rewrite all outgoing HTML code. We want to search out all static content (in this example .jpg and .png files) and rewrite it on the fly to be downloaded from a CDN. So, first we want to set the proper precondition. Loads of data leaves a webserver, so let’s make sure we only look at the relevant parts of it. We start by setting up a precondition:

<preConditions>

      <preCondition name="CheckHTML"> 

           <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" /> 

      </preCondition> 

</preConditions> 

Now we’re looking at all HTML only it’s time to get even more specific. Outbound rules allow you to filter a tag you want to look for. In this case we assume all images are located in tags. So we can use the following filtering before actually matching it to a pattern:

<rule name="CDN"stopProcessing="false">  
      <match filterByTags="Img" pattern="(https?:\/\/www.(.*)\.(jpg|png))" />  
      <action type="Rewrite" value="http://cdn.{R:2}.{R:3}" />  
 </rule> 

Noticed the ugly regex I used there? Let’s take a look at it:

(https?:\/\/www.(.*)\.(jpg|png))

All this baby does is matching all url’s containing .jpg or .png on the end. So basically it makes sure we catch all outgoing image url’s before they reach the browser. This same regex gives us 3 backreferences. We only need two of them: {R:2} and {R:3}. These contain (in my case) the stripped url (no more http://www.) and the extension. We use these later on to rebuild the url for our CDN. You might want to adjust this regular expression to suit your specific needs.

For me: this one is all I need. Now it’s time for rewriting our url. I can use the backreferences that are given to re-assemble the image location to something that should be working on the CDN. How the data gets there is up to you. I’m only pointing out how you can redirect traffic there ;) After your done, the following can be used in your web.config:

<rewrite> 

      <outboundRules>

          <rule name="CDN" preCondition="CheckHTML" stopProcessing="false"> 

                <match filterByTags="Img" pattern="(https?:\/\/www.(.*)\.(jpg|png))" /> 

                <action type="Rewrite" value="http://cdn.{R:2}.{R:3}" /> 

           </rule> 

           <preConditions> 

                <preCondition name="CheckHTML"> 

                     <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" /> 

                </preCondition> 

          </preConditions> 

      </outboundRules>

</rewrite>



IIS 7 Hosting Spain - HostForLIFE.eu :: Web Deploy Checklist for Deploying Website to IIS 7 from Visual Studio and TFS

clock March 5, 2014 07:51 by author Peter

Web Deploy is one of the mechanisms to publish websites to IIS from Visual Studio. You can utilize this mechanism to publish from Visual Studio, TFS or manually if you have existing website packaged as a zip file.  If you haven’t checked this gem of resources (Vishal Joshi's Blog) on web deploying and publishing then please do yourself a favor.  In this post I am going to talk about a checklist to make sure before you wish to publish site to IIS hosting.  Here is the list:

Installed the latest Web Deploy on windows server (Check this IIS website).

- Web Management Service is started and running

- Web Deployment Agent Service started and running

- Created a website inside IIS and created application pool for it.

- Given the user IIS Manager Permissions at the site level inside IIS

- Configured website for Web Deploy publishing

- Saved Web publish settings on a local desktop

- Import Web publish settings from the local desktop from Visual Studio publish dialog

- Publish url is over Https 

- Checked connectivity to the site from the Visual Studio publish dialog 

Now before you jump on to the TFS side of things to publish, please make sure that you have done following things:

- Team Foundation Server Build service account is added to IIS Manager Permission section for the website inside IIS

- Able to publish successfully from visual studio using web deploy?

- Check the MSBuild parameters for web deploy (I have provided what works for me below).

If you have some more checklist you have formed over the years then let me know I will add to this list.

What-If-Error
When you click publish from visual studio you will have to select a publish method and at that point select Web Deploy.  You have the option to import the profile you have created from that publish dialog.  This will pre-populate all the details.  You will have to provide the user name and password for the user who has the permission in IIS Manager Permissions as described in earlier.  At this point if you see any errors then this is a nice website where all the errors are listed.  I think you will see these errors only if you do some mistake while manually typing out the details in the publish dialog.  I haven’t found any issues if you import site details through import mechanism.
Here are TFS MSBuild parameters I use to publish a website from TFS to IIS7.
/p:DeployOnBuild=True
/p:DeployTarget=MsDeployPublish
/p:CreatePackageOnPublish=True
/p:MSDeployPublishMethod=WMSVC
/p:MSDeployServiceUrl=https://ServerName:8172/MSDeploy.axd /p:DeployIisAppPath="NameofWebsiteOnIISServer"
/p:AllowUntrustedCertificate=True
/p:UserName="domain\serviceaccount"
/p:Password="AwesomeSecurePassword"


If you are still unsuccessful in publishing the website from TFS Build then it could be that your TFS Build server is 2010 and you are using Visual Studio 2012 and it might be missing some binaries.  If you install Visual Studio 2012 on the build server then this issue could be resolved.



About HostForLIFE.eu

HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

We have offered the latest Windows 2016 Hosting, ASP.NET Core 2.2.1 Hosting, ASP.NET MVC 6 Hosting and SQL 2017 Hosting.


Tag cloud

Sign in