MVC5 get profile from custom membership

121 Views Asked by At

I'm trying to use the ´Profile´ variable using mvc5 and custom profile

web.config

<authentication mode="Forms">
      <forms loginUrl="~/Account/Login" timeout="2880" enableCrossAppRedirects="true" />
    </authentication>
    <sessionState mode="SQLServer" allowCustomSqlDatabase="true" sqlConnectionString="Data Source=190.160.10.3;Initial Catalog=eAgencia;User ID=sa;Password=nopass" cookieless="false" timeout="60" />
    <roleManager enabled="true" defaultProvider="CustomizedRoleProvider">
      <providers>
        <add name="CustomizedRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="userAuthentication" applicationName="iSessions" />
      </providers>
    </roleManager>
    <membership defaultProvider="CustomizedMembershipProvider">
      <providers>
        <add name="CustomizedMembershipProvider" type="System.Web.Security.SqlMembershipProvider" passwordFormat="Clear" connectionStringName="userAuthentication" applicationName="iSessions" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" />
      </providers>
    </membership>
    <profile enabled="true" defaultProvider="TableProfileProvider">
      <providers>
        <clear />
        <add name="TableProfileProvider" type="Microsoft.Samples.SqlTableProfileProvider" connectionStringName="userAuthentication" table="aspnet_CustomProfile" applicationName="iSessions" />
        <add name="StoredProcedureProfileProvider" type="Microsoft.Samples.SqlStoredProcedureProfileProvider" connectionStringName="userAuthentication" setProcedure="setCustomProfileData" readProcedure="getCustomProfileData" applicationName="DatabaseProfileProviderTest" />
      </providers>
      <properties>
        <!-- config to retrive table provider -->
        <add name="MemberId" type="int" customProviderData="MemberId;int" />
        <add name="Nombres" type="string" defaultValue="[null]" customProviderData="Names;varchar" />
        <add name="Lastnames" type="string" defaultValue="[null]" customProviderData="Lastnames;varchar" />
        <add name="cod_emp" type="int" defaultValue="[null]" customProviderData="cod_emp;int" />
      </properties>
    </profile>

AccountController

[HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (Membership.ValidateUser(model.UserName, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);

                    if (Url.IsLocalUrl(returnUrl))
                        return (ActionResult)Redirect(returnUrl);;

                    return Url.IsLocalUrl(returnUrl)
                               ? (ActionResult)Redirect(returnUrl)
                               : RedirectToAction("Index", "Home");
                }
                ModelState.AddModelError("", "El usuario o contraseña utilizados son incorrectos.");
            }

            return View(model);
        }

But, when I try to get the ´Profile´ using ´c#´ I get:

Profile 'Profile' threw an exception of type 'System.Configuration.ConfigurationErrorsException' System.Web.Profile.ProfileBase {System.Configuration.ConfigurationErrorsException}

In ´mvc4´ this code works, but using ´mvc5´ the profile variable, gets this error.

How I can get the profile using custom membership?

0

There are 0 best solutions below