asp.net – 使用成员资格数据在aspnet_profile表中存储其他数据
发布时间:2020-12-16 07:04:06 所属栏目:asp.Net 来源:网络整理
导读:我在基于MVC2框架的项目中使用了带有OpenId实现的Membership API. 除了用户名之外,我还需要在注册时将一些其他字段与用户相关联. 我不确定但是我认为asp.net中的Profile系统是为这种类型的要求而构建的.另外,我看到一个包含名为’aspnet_profile’的其他成员
我在基于MVC2框架的项目中使用了带有OpenId实现的Membership API.
除了用户名之外,我还需要在注册时将一些其他字段与用户相关联. 我不确定但是我认为asp.net中的Profile系统是为这种类型的要求而构建的.另外,我看到一个包含名为’aspnet_profile’的其他成员资格表的表. 我在应用程序web.config中添加了以下设置以启用配置文件: <profile enabled="true"> <properties> <add name="FullName" allowAnonymous="false"/> </properties> </profile> 如前所述,应用程序需要一些额外的数据与用户相关联,因此在使用Membership API创建用户时,我添加了几行代码以进入配置文件表 System.Web.Security.MembershipCreateStatus status = MembershipService.CreateUser(userModel.UserName,userModel.Password,userModel.UserName); if (status == System.Web.Security.MembershipCreateStatus.Success) { FormsService.SignIn(userModel.UserName,true); Session["Username"] = userModel.UserName; dynamic profile = ProfileBase.Create(MembershipService.GetUser(userModel.UserName).UserName); profile.FullName = userModel.UserFullName; profile.Save(); RedirectToAction("Tech","Home"); } 但我没有看到数据库中的aspnet_profile表中添加了任何行.另外,我想询问这是否是添加其他数据以及默认成员资格数据的首选方式 解决方法
我通过在web.config中进行与默认配置文件提供程序名称相关的一些更改来使其工作:
<profile enabled="true" defaultProvider="AspNetSqlProfileProvider"> <providers> <clear/> <add name="AspNetSqlProfileProvider" applicationName="/" connectionStringName="ApplicationServices" type="System.Web.Profile.SqlProfileProvider" /> </providers> <properties> <add name="FullName" allowAnonymous="false"/> </properties> </profile> 另外,我在调用ProfileBase.Create函数和设置Profile.FullName之间再添加一行; profile.Initialize(userModel.userName,true); 我终于在aspnet_profile表中看到了一个新注册用户的条目:) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc-3 – 如何注入依赖项到global.asax.cs
- asp.net-mvc – ASP.NET MVC 5自定义错误页面
- 在asp.net上调用两个函数按钮onclick
- asp.net-mvc – 通知面板类似于stackoverflow的
- 实体框架 – 带MVC3的EF4 – 我需要存储库模式吗?
- asp.net-mvc-2 – 在ASP.NET MVC2中向客户端返回http 204“
- 在ASP.NET MVC3中实现的示例项目插件jquery文件上传插件
- asp.net – Dropdownlist在Page_ClientValidate()之后不回发
- asp.net-mvc-4 – 实体框架代码第一个多对多关系和继承
- 如何在运行时将ASP.Net控件移动到Web窗体上的不同位置?
推荐文章
站长推荐
热点阅读