Wednesday, June 13, 2012

Deploy your Website Using IIS 7 - Part I

As an industry best practice, developers should not have access to the Production server.  Developers can use Dev servers as their playground and build any number of proofs-of-concept.  And developers can perform any number of tests on the Test servers.  But, while developers need to deploy websites from the Test environment to the Production environment, they need not be granted direct access to the Production servers.

There are a number of ways to deploy a website to the secure Production environment.  My prefered method is to export a package of my website from IIS 7 in the Test server.  I can then import this package into the IIS 7 of the Production server.  All files in the package contents would be identical in both environments. 

Of course, you would not want the web config files in one environment to be copied to the other.  The same is true for SSL Certificates and other environment-specific files.  Not to worry: you can exclude them from the package you export.

This blog will help you create a package of your website using the IIS Manager and the Web Deployment Tool in IIS 7.0 or above.

Export a Package


1. Always make a backup of your Production web server, in case a website deployment to Production fails, and a rollback becomes necessary.  Run the following command to backup the IIS server:
%windir%\system32\inetsrv\appcmd add backup “PreMsDeploy”

2. Open the IIS Manager by clicking Start -> Run and typing INETMGR

3. In IIS Manager, in the Connections pane, select the Server node

4. In the right-hand Actions pane, under Deploy, click the Export Server Package… link to launch the wizard




5. In the Export Server Package dialog, Select All the Contents of the Package



6. Click Next

7. In the Select Parameters dialog, select no parameters.  Click Next




8.  In the Save Package dialog, click the Browse button to choose a location to save your exported package.  The Package name must have a ZIP file extension.  For this example, “2012-07-09 IISBackup.zip” is used




9. Enter the Encryption Password



10.  The wizard will now complete the packaging process and save the package to disk.  When it is complete, a Summary page documents an overview of what actions were performed.  Click Finish.




That's it.  You have now created an exported package of your website using IIS 7 Manager.

In Part II, we will walk through the steps to import this package from the Test server into the Production server.









Tuesday, June 12, 2012

ASP.NET SQL Server Database Installation

Beginning with the .NET Framework 2.0, ASP.NET has a rich new infrastructure that provides for a number of built-in features that would otherwise cost developers a lot of time and effort to build on their own.  These features include Membership, Role Management, Profiles, Web Parts Personalization, and Health Monitoring, among others.

To avail of these features, we will first need to install the Microsoft SQL Server database used by the SQL Server providers in ASP.NET.  We can use the ASP.NET SQL Server Registration Tool to
create this SQL Server database called ASPNETDB. 

The ASP.NET SQL Server Registration Tool file name is ASPNET_REGSQL.EXE

Pre-Requisites


The Pre-Requisites for running this tool include the following:

   a) Set execution policy (beyond machine default)
       e.g. set-executionpolicy -scope CurrentUser -executionPolicy Undefined

   b) .Net Framework 2.0 or later

   c) Installation User must be a DBO Sysadmin on SQL Server Instance (install creates a database)

Installation Procedures


As a best practice, you should run the ASP.NET SQL Server Registration tool from the Database server – not the Web server. 
The Aspnet_regsql.exe file is located in the [drive:]\%windir%\Microsoft.NET\Framework\v4.0.30319 folder on your server.

You can run Aspnet_regsql.exe without any command-line arguments to run a wizard that will walk you through specifying connection information for your SQL Server installation, and installing the database elements for the Membership, Role Management, Profile, Web Parts Personalization, and Health Monitoring features.

The wizard will walk you through the following steps:



Click Next.



Click Next.



Enter the Server info and authentication info and keep the Database <default> value.  Click Next.
Follow the rest of the wizard steps until completion.

Verification Procedure


To verify the success of the installation of the ASP.NET Database, you may do the following steps.

1) Go to SQL Server Management Studio

2) Log in to the appropriate database server



3) Verify that the tables in the image below exist.



4) Run a simple query against the dbo.aspnet_Users table to test the connection.  If no errors are thrown, then the installation was successful

Monday, June 11, 2012

Test HTTPS in your Test Environment

Most public websites today support the HTTPS protocol to communicate securely with their web users.  Such websites have an SSL (Secure Socket Layer) Certificate installed on their production web server.  If you are building a website that would implement the HTTPS protocol, then it would make sense to implement HTTPS in your Development environment and your Test environment as well as your Production environment. 
In your Dev and Test environments, you can use a mock (self-signed) SSL certificate.  But for your Production environment, you will need an SSL certificate from a Certification Authority like VeriSign or GoDaddy.
To implement HTTPS in your Dev or Test environment, you can perform the following steps.

1)     In IIS Manager, at the server level, in the Features View, select the Server Certificates feature.
                                              

2)     In the Actions pane, double-click Create Self-Signed Certificate

3)     Enter a name like MyWebDevCertForIIS or MyWebTestCertForIIS


 
4)     Back in the Connections pane, select your website, and in the Actions pane, under Edit Site, double-click Bindings



5)     Click Add to add a Binding
 
6)     In the Add Site Binding dialog, select https type, port 443 and the appropriate SSL Certificate (i.e. MyWebDevCertForIIS)

7)     The web application now has the correct protocol bindings