Story Details for tools
MvcInstaller for .Net 4 and 4.5 with VS 2012
Note: this version of MvcInstaller is recommended to be used with SecurityGuard.Mvc4. If you don't you will most likely experience the exception about "ExtendedMembershipProvider". See Issues at the bottom of this article for more information.
MvcInstaller for .Net 4.0 and 4.5
I've made some changes to MvcInstaller for these versions of the .Net Framework, mostly to address the new System.Web.Providers namespace that is used instead of the older System.Web.Security namespace.
This new version is also now available via NuGet.
Here's a good starter article by Scott Hanselman. http://www.hanselman.com/blog/IntroducingSystemWebProvidersASPNETUniversalProvidersForSessionMembershipRolesAndUserProfileOnSQLCompactAndSQLAzure.aspx
Here's a look at the new System.Web.Providers database schema.
There's no table name prefixes (aspnet_). They are a lot cleaner. For those who used the WebEvent table, you'll need to make that yourself unfortunately.
Special NoteThis version of MvcInstaller is an enhanced version of the Mvc3 version. Some of the description has not been repeated here, so you may want to read that article first to get the basic information.
Also, MvcInstaller updates your web.config file. This is to make your life easier. Here's what gets modified:
- ConnectionString section - one or two connection strings will be added to your application based on whether you are using the Entity Framework. One connection string will be for the Entity Framework related connection string, and the other will be used by the Membership system.
- AppSettings - a new key will be added call "AppInstalled". It will have a value of "false" which will tell MvcInstaller that it is OK to run. Once MvcInstaller is executed and runs successfully, it will remove this key and prevent MvcInstaller from being executed again. This is a security feature to prevent others from accidentally or maliciously re-installing the application again.
No other sections are updated in the web.config. If you don't want your web.config to be modified, then you should not use MvcInstaller!
What is MvcInstaller?
For those of you who haven't used MvcInstaller for MVC, I'll recap. MvcInstaller is a little NuGet package that helps you install your MVC application on a staging or production server quickly and easily.
It can also install the complete ASP.NET Membership system in your database along with your application's database schema and seed data. And it can do it literally in 10 seconds or less.
How it works
When you install the NuGet package it installs a bunch of files that you use to configure your installation. The primary file you will work with is the installer.config file. It's an xml file where you enter your settings for database connection, application name, and other things that are pertinent for the Membership system, if you so desire to have it installed.
It will also add a new key to the appSettings section.
This key tells MvcInstaller it's OK to execute. If it's gone (or true) then it tells MvcInstaller that it has already executed and MvcInstaller removes this key. When this key is removed, it prevents the /Install view from being shown. This is a security measure to prevent accidental re-installation of the database.
When you configure the installer.config file with your database connection information, you can then deploy your compiled MVC application to any server to have it installed. Simply FTP it to the server, navigate to the /Install view and you will see a page that displays the settings in the installer.config file. But it won't show the passwords or any other sensitive information. This way you can install it in front of someone without concern that they may see your passwords.
Once you click the "Install" button, it will do the following:
- Build the connection string section for you
- Place the Membership values from the settings file into the Membership sections
- Do some basic validation before executing
- If it validates, it will create the Membership database, if you want it created
- It creates Users and Roles and assigns the Users to the Roles
- It will create your database from the SQL files you provide
- That's it!
Be sure to watch the video demonstration to get a better idea of how it works.
IMPORTANT NOTE!!! One thing I should point out is that at the moment it only works with Forms Authentication. I have not yet tested it to work with Windows Authentication. That is on my TODO list, I just haven't found time.
There are a number of things I've done with this version to accommodate both .Net 4.0 with VS 2010 MVC applications, and .Net 4.5 with VS 2012 MVC applications. Here's a quick list:
- Include provider "types" in default installer.config file
- Add new SessionState section in installer.config file
- Generate Membership web.config sections with the new System.Web.Providers namespace
- Detect default conventions in VS 2012 and handle appropriately
Here's a look at the new installer.config file.
You'll notice that each of the Membership elements now have the "type" attributes set to the default for this new namespace. MvcInstaller will insert these values directly into your web.config Membership sections for you, along with any other pertinent data.
Note: MvcInstaller updates your web.config Membership sections!
Again MvcInstaller takes the values from the installer.config file and updates your web.config file for you. It only makes these modifications to make your life easier and to make sure they are setup correctly to work with your application.
It updates the connectionString section and the membership sections by updating the connectionStringName and applicationName attributes.
NOTE: all the changes made by MvcInstaller are completely modifiable by you afterward. And there is nothing done to your web.config that is proprietary to MvcInstaller. Everything done is standard .Net protocols.
How to Deploy to Server
Deployment to your production or staging server is easy, it's as simple as just FTP'ing your site to the server. But there are some things to know to make sure you haven't missed something.
1) If you have used MvcInstaller to configure your Membership database on your local development server, then you need to make sure you update your appSettings section to add back in the "AppInstalled" key.
MvcInstaller needs this key to exist in order to execute, AND it needs to have a value of "false", meaning the app has not been installed. This will allow MvcInstaller to display the /Install view.
2) Update the installer.config. Make sure you've updated the production version of the installer.config file to reflect the settings for your production SQL Server database connection information. These values will update the web.config/ConnectionStrings section on the production server, as well as the Membership sections, so you don't want to leave the development settings in there.
3) Compile your MVC application with the new installer.config and web.config modifications as described above, then copy the application to the server, either via FTP or some other method.
4) Modify the permissions for the site to allow for Write permissions. This is only needed during MvcInstaller execution for it to update the web.config file. Once it's updated, you can revert the permissions back.
5) Once the application is on the server, open it in a browser and make sure you can see the home page, and then navigate to http://www.yourdomain.com/Install. The MvcInstaller view should appear with the settings for your production database. Confirm all the settings are correct and click the button to execute.
Everything should run successfully!
If you get an error, you can post it here and I'll try to help you fix it as much as possible.
Handle VS 2012 projects
In VS 2012 MVC projects, the web.config file is void of the Membership sections, that's because it is using a new Membership system based on the SimpleMembershipProviders. This I'm not such a big fan of just yet, but more on that later.
Since VS 2012 projects use this new namespace means it also uses a new database schema, one that is radically different than previous. There are also new means for initialization and activation which I'm finding difficult to use in a custom scenario.
Here's a look at this database schema:
I don't really have a problem with the new schema or it's intentions, which is to allow for other platforms such as Azure, etc., I just find a lack of helpful documentation on how to use it in non-"default" scenarios, disappointing.
For these reasons I've tested MvcInstaller using the .Net 4.0 SQL Server schema used by the System.Web.Providers namespace and they all work perfectly. So until I figure out what the hell I'm doing with this new SimpleMembershipProviders namespace, I will be installing the Membership database with the System.Web.Providers namespace.
I hope to be figuring this out soon so I can release a version of MvcInstaller specifically for VS 2012 to use the SimpleMembershipProviders namespace.
My Take on the SimpleMembershipProviders Integration
My initial complaint with this is that I can't get it to work quickly and easily outside of the default scenario, despite the fact that I have a 500 IQ.
Seriously though, I'm going to reserve my real feelings about this new framework until I do some more investigation, but at first look, it feels to me that Microsoft may have dropped the ball with this one. Again mostly because I can't find reliable documentation on the providers.
Some of my complaints are:
- it seems to be tightly-coupled with a DbContext.
- new hoops to jump through to create the database schema
- in-code connection string initialization
- LazyInitializer? What?
There may be more, but my eyes are glazing over at the moment thinking about this. ;^) But really, these are just my complaints, they are not yet objections since I don't know enough about how this new framework works to object that strongly.
For the time being MvcInstaller for .Net 4.x will be using the System.Web.Providers namespace and database schema. Don't expect to use it right now with the new SimpleMembershipProviders namespace. That version will be coming soon, hopefully.
I've tested this a number of times in both VS 2010 and VS 2012 with both frameworks and got it working. Please help me out and post any bugs you may find here so I can make it better.
Also this works with the companion package: SecurityGuard.Mvc4
Setup Azure for MvcInstaller.Mvc4 installation
This is information provided by Pratheek Khoosal on how to use MvcInstaller.Mvc4 with Windows Azure.
The following are steps to take to prepare Azure for the web site and deployment:
- When creating the Azure website, use the custom create as illustrated
This will create the Azure database and website link
- Once the website and database have been created. Select the relevant database, this in turn will make available the database management features. Select the Manage allowed IP address option.
- Allow your current client IP address to manage the database
- From the Azure website management interface use the select the Download publish profile option to your local machine
- In Visual Studio right click your project in the solution explorer, select the Publish option, using this option publish the website using the downloaded file from the previous step
Use MvcInstaller to install database to Azure
These are the instructions to use MvcInstaller.Mvc4 to install the database on Azure.
- I setup MvcInstaller, exactly as I would locally except I changed my database connection string to point to the Azure database, in the installer.config
All the text in italics is what I changed
- I then ran the application on localhost changed the url to install and installed the application as if I am installing it locally.
What this did was connect to the Azure Db and install all the relevant database compontents and users.
I hope this helps users to plan on using it with Windows Azure.
To call this method, the "Membership.Provider" property must be an instance of "ExtendedMembershipProvider".
This error is usually seen after installing MvcInstaller.Mvc4 and then trying to Register or Login a user. Since MvcInstaller.Mvc4 uses the System.Web.Providers namespace for Membership, and the VS 2012 projects use the Membership system based off of the SimpleMembershipProvider namespace, you will see this exception.
This is due to the fact that clicking the Register or Login links will point to the Account controller which initializes the SimpleMembershipProvider with the InitializeSimpleMembership attribute. And the SimpleMembershipProvider inherits from the ExtendedMembershipProvider class.
MvcInstaller.Mvc4 updates the web.config membership sections to use the System.Web.Providers namespace and this causes the conflict. You need to point to a controller that does NOT use the SimpleMembershipProvider namespace.
The Easy fix is to simply install my SecurityGuard.Mvc4 NuGet package and update the LoginPartial view to point to the SGAccount controller. Everything will work.
The other option is to create your own provider that inherits from ExtendedMembershipProvider and remove the membership sections in the web.config. Although, this hasn't been tested so you're on your own for now.
My Suggestion: install SecurityGuard.Mvc4.
==== Update for Version 1.1.1 ====
- Changed the link to SecurityGuard in the /install/index.aspx view from /SGAccount/LogOn to /SGAccount/Login to match the changes made in SecurityGuard.Mvc4.