How to Setup Mvc Installer

MvcInstaller was built to be easily plugged into any ASP.NET MVC 2 or higher application.

You apply these instructions to your pre-release version of the application.  In other words, you incorporate the MvcInstaller into your release version of the application that will be deployed to your server.

Follow these instructions which will get you up and running in just a few minutes.

1 - Download

Download the MvcInstaller-binary.zip file to quickly use it in your application. (Download the source files to examine the source code and use that compiled assembly).

2 - Unzip

Unzip the binary zip file to you hard drive.  This file will contain a few files.

winzip-opened_thumb3

 

3 – Reference In Visual Studio

Once the zip file is extracted on your hard drive, open your Mvc application in Visual Studio and make a reference to the MvcInstaller assembly.

4 – Copy the installer.config

Next, copy the installer.config file into the root of your Mvc application.  It contains the basic schema used in the configuration and you will need to modify it for your application needs.

The installer.config file will look something like this:

Code Snippet
  1. <?xml version="1.0"?>
  2. <InstallerConfig>
  3.   <Path>
  4.     <RelativeSqlPath>App_Data</RelativeSqlPath>
  5.   </Path>
  6.   <Membership Create="true" ProviderName="MyAspNetMembershipProvider">
  7.     <Roles>
  8.       <Role Name="SuperAdministrator">
  9.         <Users>
  10.           <User UserName="superadmin" Password="i234567" Email="sa@email.org" SecretQuestion="Pets name" SecretAnswer="Thor" />
  11.         </Users>
  12.       </Role>
  13.       <Role Name="Administrator">
  14.         <Users>
  15.           <User UserName="admin" Password="234566y" Email="admin@email.org" SecretQuestion="Favorite color" SecretAnswer="Taupe" />
  16.           <User UserName="byron" Password="93o404u" Email="byron@email.org" SecretQuestion="Favorite Movie" SecretAnswer="Saturday Night Fever" />
  17.         </Users>
  18.       </Role>
  19.     </Roles>
  20.   </Membership>
  21.   <Database UseTrustedConnection="true">
  22.     <ConnectionStringName>MyDbConnection</ConnectionStringName>
  23.     <DataSource>localhost</DataSource>
  24.     <InitialCatalog>MyCoolDb</InitialCatalog>
  25.     <UserName>mycooldbadmin</UserName>
  26.     <Password>mycooldbpassword</Password>
  27.   </Database>
  28. </InstallerConfig>

You need to substitute your values with the existing values.

Roles

You can add as many roles to the config file as needed inside the Roles node.

Users

You can add as many users as you need inside the Users node.  Keep in mind the way the users are nested inside the Role node.  Make sure you enter a User inside the Role they will be assigned to.

RelativeSqlPath

Inside the Path node the RelativeSqlPath points to the folder inside the root of your Mvc application where you have copied your sql scripts to create your database and any data you want inserted.  Since this is a relative path, there is no need for a leading slash (\).  In the example above, the “App_Data” folder will be found under the root of your web application. 

If you wanted to save them in a folder called “App_Data\SqlScripts”, then simply enter “App_Data\SqlScripts” inside the RelativeSqlPath node, with no quotes.

Database

The database node is pretty straight forward.

  • UseTrustedConnection – set this to “true” if you are using a trusted connection, or “false” if you are using database user credentials.
  • ConnectionStringName – enter the name of your chosen connection string name.  This will be placed in the connection string of the web.config file.
  • DataSource – this is the name of the SQL Server instance that will be used.  You can enter any valid instance name or IP address.
  • InitialCatalog – this is the name of the database.
  • UserName – this is the SQL Server login created that is attached to this database.
  • Password – this is the SQL Server password created that is attached to this database.

Make sure you save the file in the root of the Mvc application .

5 – Installer View

Copy the /Views/Install/index.aspx page and folder into the Views folder.  If you are using a custom ViewEngine, place this file appropriately for your view engine.  You may need to modify the MasterPage directive of the file for it to work.

(Optional) – to make this page look correctly, you can copy the CSS file into your project and reference it in the MasterPage.

6 – AppSettings modification

The last thing is to create a new key in your appSettings section of the web.config file.  It should look like this.

Code Snippet
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <appSettings>
  3.   <add key="AppInstalled" value="false"/>
  4. </appSettings>

This setting is read by the installer and it determines whether the installer has been run yet.  The only valid value for this is “False”.  If the key is either “true” or removed from the appSettings section, then the installer will assume that application has already been installed.

When the installation process is completed, it will remove this key as a security measure.  This will prevent others from simply entering into their browser something like, http://www.yourdomain.com/install and have your installation page appear.

Another security measure would be to remove the installer.config file after the installation has completed successfully.

Now you are ready to run it.

Last edited Nov 21, 2010 at 9:48 PM by kahanu, version 1

Comments

No comments yet.