【问题标题】:ASP.NET MVC 4 Membership profile agasint mysql针对 mysql 的 ASP.NET MVC 4 成员资格配置文件
【发布时间】:2012-10-18 19:26:00
【问题描述】:

我想做的就是为用户添加个人资料,以便在他们的帐户中时,他们可以更新他们的个人资料。

我需要对 mysql 执行此操作。

此时,我什至会举一个使用 MSSQLServer 的工作示例。

我寻求关于如何做到这一点的单一教程,因为两天的尝试拼凑起来终于打破了我的意愿。有人...?

【问题讨论】:

    标签: mysql asp.net-mvc-4 asp.net-membership asp.net-profiles


    【解决方案1】:

    在 web.config 中注册一个配置文件提供者

    <profile>
          <providers>
            <clear/>
            <add name="AspNetSqlProfileProvider"
                 type="System.Web.Profile.SqlProfileProvider"
                 connectionStringName="ApplicationServices" 
                 <!--same connection string as the membership provider-->
                 applicationName="/"/>
          </providers>
          <properties>
            <add name="FirstName" type="string"/>
            <add name="LastName" type="string"/>
            <!--...or whatever profile properties you want/need-->
          </properties>
        </profile>
    

    设置配置文件属性

    ProfileBase profile = ProfileBase.Create(userName);
    profile["FirstName"] = "John";
    profile["LastName"] = "Smith";
    

    阅读它们

    string firstName;
    string lastName;
    ProfileBase profile = ProfileBase.Create(userName);
    firstName = profile["FirstName"] as string,
    lastName = profile["LastName"] as string,
    

    【讨论】:

    • 运行以下命令时:ProfileBase profile = ProfileBase.Create(User.Identity.Name); profile["FirstName"] = "James";单步执行代码,User.Identity.Name 返回登录用户的正确用户 ID。但是,一旦执行 profile["FirstName"] = "James" 行,就会引发以下错误:错误:无法从数据库中检索配置文件数据。 web.config 中的配置文件提供程序配置为已发布。
    • @John 你在使用默认的会员服务提供商吗?该错误可能是数据库连接问题。您可以发布您的网络配置的 部分吗?
    【解决方案2】:

    请检查 web.config 中的所有内容是否拼写正确,我遇到了同样的错误,并且是“connectionStringName”属性中的问题。

    我刚刚发现它下载了 MySQL.Web 源代码并替换了我项目中的 dll,我可以看到真正的错误,而不仅仅是一般异常。

    【讨论】:

      猜你喜欢
      • 2012-09-05
      • 1970-01-01
      • 1970-01-01
      • 2011-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多