【发布时间】:2012-10-18 19:26:00
【问题描述】:
我想做的就是为用户添加个人资料,以便在他们的帐户中时,他们可以更新他们的个人资料。
我需要对 mysql 执行此操作。
此时,我什至会举一个使用 MSSQLServer 的工作示例。
我寻求关于如何做到这一点的单一教程,因为两天的尝试拼凑起来终于打破了我的意愿。有人...?
【问题讨论】:
标签: mysql asp.net-mvc-4 asp.net-membership asp.net-profiles
我想做的就是为用户添加个人资料,以便在他们的帐户中时,他们可以更新他们的个人资料。
我需要对 mysql 执行此操作。
此时,我什至会举一个使用 MSSQLServer 的工作示例。
我寻求关于如何做到这一点的单一教程,因为两天的尝试拼凑起来终于打破了我的意愿。有人...?
【问题讨论】:
标签: mysql asp.net-mvc-4 asp.net-membership asp.net-profiles
在 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,
【讨论】:
请检查 web.config 中的所有内容是否拼写正确,我遇到了同样的错误,并且是“connectionStringName”属性中的问题。
我刚刚发现它下载了 MySQL.Web 源代码并替换了我项目中的 dll,我可以看到真正的错误,而不仅仅是一般异常。
【讨论】: