Search code examples
asp.net-mvc-2web-configmembership-providerroleprovider

asp2 roles and membership settings in web.config


How can i set up web.config file to support user membership with roles for my mvc page with only database file as i do not have access to sql server at the moment.

<authentication mode="Forms">      
  <forms loginUrl="~/Account/LogOn"
     protection="All"
     timeout="30"
     name="AppNameCookie"
     path="~/Account/LogOn"
     requireSSL="false"
     slidingExpiration="true"
     defaultUrl="default.aspx"
     cookieless="UseCookies"
     enableCrossAppRedirects="false" />
</authentication>

<membership defaultProvider="MyMembershipProvider">
  <providers>
    <clear/>
    <add name="MyMembershipProvider" type="NudaJeFuc.WebUI.Classes.MyMembershipProvider"
         enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
         maxInvalidPasswordAttempts="5" MinRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
         applicationName="/" />
  </providers>
</membership>

<profile>
  <providers>
    <clear/>
    <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
  </providers>
</profile>

<roleManager>
  <providers>
    <clear/>
    <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
    <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
  </providers>
</roleManager>

<pages>
  <namespaces>
    <add namespace="System.Web.Mvc" />
    <add namespace="System.Web.Mvc.Ajax" />
    <add namespace="System.Web.Mvc.Html" />
    <add namespace="System.Web.Routing" />
    <add namespace="NudaJeFuc.WebUI.HtmlHelpers"/>
  </namespaces>
</pages>


Solution

  • Your web.config looks fine, but you need to set up a connectionString (in your case named ApplicationServices) to point to Sql server that will store membership database.

    You can create membership database using a wizard, just run aspnet_regsql from VS cmd. You can read more on MSDN.