MVC5从自定义成员资格获取配置文件

时间:2017-07-25 20:11:29

标签: c# asp.net-mvc-5 custom-membershipprovider

我正在尝试使用mvc5和自定义配置文件

来使用'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);
        }

但是,当我尝试使用'c#'获得'Profile'时,我得到了:

  

Profile'Profile'抛出类型'System.Configuration.ConfigurationErrorsException'的异常System.Web.Profile.ProfileBase   {System.Configuration.ConfigurationErrorsException}

在'mvc4'中,此代码可以正常工作,但使用'mvc5'这个配置文件变量会出现此错误。

如何使用自定义会员资格获取个人资料?

0 个答案:

没有答案