3.08.2013

How To Setup SecurityGuard.MVC4 And MvcInstaller.MVC4 For ASP.NET MVC 4 Application

I love this open source project called SecurityGuard.  It is a complete ASP.NET Membership management system plugin for ASP.NET MVC 4 application.

To install via NuGet:
PM> Install-Package SecurityGuard.MVC4
To make it easier to create and setup the Membership database tables and roles, I recommend to use another Nuget package called MvcInstaller.MVC4:
PM> Install-Package MvcInstaller.MVC4
Follow these steps to setup SecurityGuard.
Follow these steps to setup MvcInstaller.

For the MvcInstaller, the following requirements should be met prior to running the installer for the first time:

1. Create the database, and make sure to create the db login account to be used in accessing this database.
2. Modify the installer.config file, example is as follows:
<installerconfig>
  <applicationname>ProductCoC</applicationname>
  <path>
    <relativesqlpath>App_Data</relativesqlpath>
  </path>
  <membership create="true" providername="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
  <profile providername="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
  <rolemanager providername="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
    <roles>
      <role name="Administrator">
        <users>
          <user email="sammydc@mail.com" password="ProductCoC" secretanswer="Green" secretquestion="Favorite Color" username="WBI\sammydc">
        </user></users>
      </role>    
      <role name="SecurityGuard">
        <users>
          <user email="sammydc@mail.com" password="ProductCoC" secretanswer="Green" secretquestion="Favorite Color" username="WBI\sammydc">
        </user></users>
      </role>
    </roles>
  </rolemanager>
  <sessionstate providername="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
  <database usetrustedconnection="false">
    <connectionstringname>MembershipConnection</connectionstringname>
    <datasource>MSSQ4\Instance1</datasource>
    <initialcatalog>ProductCoC</initialcatalog>
    <username>ProductCoC</username>
    <password>ProductCoC</password>
  </database>
</sessionstate></profile></membership></installerconfig>
3. Make sure that the AppInstalled setting in web.config is set to false
<appsettings>
 <add key="AppInstalled" value="false" />
</appsettings>
4. Now deploy the MVC 4 application. After deployment, from the browser, navigate to the install path, you should see this on the browser:



5. Make sure to select Use SecurityGuard, then click Install.

6. After a few seconds, it should display a message that the installer completed successfully.

7. Check the database to make sure that the tables and users have been created, in SQL Server Management Studio, it should look like this:



8. Finally, go to /SecurityGuard/Membership/Index, this is what you should see:



Success! Now we have an instant membership management for our app.

Issues encountered during implementation and deployment:

1. When I deployed this to the production server, I got an error like below because the installer.config and web.config are inaccessible:



To overcome this issue, I needed to temporarily add, the Everyone group in windows to have modify access to these files. Make sure to change back the permissions right after the setup.

2. Another issue that I encountered is that because the application is intended for the intranet and I'm using windows integrated security, there is a problem when using an account preceded by a domain name such as DOM1\sammydc, the backslash causes some issues with the UI and routing logic. I will write up the solution to this problem on my next post.

4 comments:

  1. We are the best security service provider company. We provide all types of security service. We provide personal and device security.

    Private Investigator Orlando

    ReplyDelete
  2. This is very good tutorial for setting up mvc4 application. its helpful.

    Thaak you

    ReplyDelete