使用MemberShip,Profile时碰上的一些问题
1. 使用Profile.GetProfile(string username)时碰上的问题<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
我想在一个页面里编辑任意一个MemberShip的User的Profile,这时我使用了页面.Profile.GetProfile(username),由于能登陆到这个页面的用户都是具有权限的用户,所以运行的时候一切正常,为了优化代码,我要把操作Profile的代码移动到后台自己定义的类里,这时候已经不存在页面类的实例,所以我要使用HttpContext.Current.Profile来代替Page.Profile 这时候问题出现了,在HttpContext.Current.Profile里不存在GetProfile(string username)这个方法,仔细看一下 原来这两个Profile是来之不同的类,Page.Profile是ProfileComm的实例,而HttpContext.Current.Profile是Profilebase的实例,最后找到得到GetProfile的方法是这样的:
ProfileCommon pc = (ProfileCommon)ProfileBase.Create(“username”, true);
而这里的username,一定是要一个通过认证的membership的user,这时候在使用pc.GetProfile(“otherusername”) 就可以对其他用户的Profile进行编辑了。
2. 使用MembershipUser.ChangePassword碰上的问题
我自定义了一个添加,修改,删除Membership用户的控件,要使用到修改密码的功能,MembershipUser里有一个ChangePassword的方法,不过需要两个参数,oldpassword和newpassword,由于我需要一个修改密码而不用提供旧密码的功能,所以就要先把用户的老密码给找出来,幸运的发现在MembershipUser下有一个GetPassword的方法,立即调用弹出异常,看了异常的说明继续找问题,发现问题出在 Membership Provider的配置参数上,
<membership defaultProvider="herSqlMembershipProvider">
<providers>
<add name="herSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" requiresQuestionAndAnswer="false" connectionStringName="her" requiresUniqueEmail="false" passwordFormat="Clear" minRequiredPasswordLength="3" enablePasswordRetrieval="true"
minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" applicationName="/ " />
</providers>
</membership>
GetPassword主要涉及到三个属性: passwordFormat, requiresQuestionAndAnswer, enablePasswordRetrieval,首先需要把enablePasswordRetrieval设置为true,可以回收密码,然后是passwordFormat可以设置三个值:Clear, Encrypted, and Hashed,如果设置成了Hashed,那密码是不可逆的,也不能得到密码,而Clear和Encrypted都是可以的,Clear是明文保存,而Encrypted是加密保存,如果设置成了加密保存,还需要设置一些密钥什么的,不然CreateUser时会出错,最后是属性requiresQuestionAndAnswer,它是表示是否需要有密码问题和答案来重新取回密码的机制,如果这个设置为true,那么你在使用GetPassword时,需要把这个用户的问题的答案一起传进去,不然也会产生异常。
3. 匿名访问时设置Profile属性出现异常
这也是需要配置文件里的属性进行配置:
<anonymousIdentification enabled="true" />
<profile defaultProvider="herSqlProfile">
<providers>
<add name="herSqlProfile" type="System.Web.Profile.SqlProfileProvider" connectionStringName="her" />
</providers>
<properties>
<add name="MyTheme" type="String" allowAnonymous="true"/>
</properties>
</profile>
首先是anonymousIdentification 把enbaled设置为true,然后再profile里的属性allowAnonymous="true"
转载于:https://www.cnblogs.com/dotLive/archive/2007/03/15/676112.html
使用MemberShip,Profile时碰上的一些问题相关推荐
- source:读取文件 “/etc/profile” 时发生错误解决办法
新装了最火的Linux发行版Manjaro,在/etc/profile中配置了JDK环境变量之后,刷新环境变量时,出现 source:读取文件 "/etc/profile" 时发生 ...
- Ubuntu读取/root/.profile时发现错误:mesg:ttyname fa
https://jingyan.baidu.com/article/fb48e8be3743696e632e1450.html gedit /root/.profile mesg n => tt ...
- 2008中的membership profile操作(转)
<profile > <properties> <add name="jimmy" /> </< span>propertie ...
- 如果使用SQLExpress 2005时要求'sp_configure 'User instances enabled''
如果在ASP.NET使用SqlExpress 2005时出现要求执行sp_configure 'user instances enabled',可以执行已下SQL语句解决 exec sp_config ...
- Membership 网站安全相关配置节
引用官方参考文章 ASP.NET成员资格功能是为了管理和授权用户,常常与窗体认证搭配使用,还有一个验证控件像Login,LoginVIew,LoginStatus,LoginName,Password ...
- Oracle profile 用户资源限制 说明
一. 官网说明 CREATE PROFILE http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/statemen ...
- Spring3.1新属性管理API:PropertySource、Environment、Profile
2019独角兽企业重金招聘Python工程师标准>>> Spring3.1提供了新的属性管理API,而且功能非常强大且很完善,对于一些属性配置信息都应该使用新的API来管理.虽然现在 ...
- 更改Webshpere的profile端口及删除profile
为什么80%的码农都做不了架构师?>>> 应用使用Websphere作为中间件,新建了个profile,准备发布,都没什么问题,但是在新建这个profile时,其他的profi ...
- iOS Provisioning Profile(Certificate)与Code Signing详解
引言 关于开发证书配置(Certificates & Identifiers & Provisioning Profiles),相信做 iOS 开发的同学没少被折腾.对于一个 iOS ...
最新文章
- 李彦宏AI布局又下一城,成立生命科学公司“百图生科”
- C++官方自带可持久化平衡树rope的3000行源码
- 数据分析师被老板问住了——场面一度非常尴尬。
- 单身两年以上是什么体验?
- 前端学习(3272):js中this的使用箭头函数
- 给正在备战秋招的同学一些小建议
- IOS开发~GCD--讲的巨详细,而且还有例子工程
- glassfish 自定义 jaas realm
- 记风雨兼程的2020年,2021年,我来了!
- 为什么要编写轻量级的View Controller??
- python实现bt下载器_10行 Python代码使用磁力链接批量下载种子
- Excel技巧—快速插入空行技巧大集合
- 超好的 MARKINGCODE查询网 电子元件丝印
- 常用电平转换电路的方法
- 解决从k8s.gcr.io拉取镜像失败问题
- 蒙特卡洛算法求矩形内切圆面积
- win10连接打印机问题:不能访问此共享文件夹
- 周期和频率之间的换算
- java多线程实现龟兔赛跑
- .vscode/extensions下放的是插件
热门文章
- wxpython应用程序对象与顶级窗口_wxPython--学习笔记
- python编码-python中处理中文编码问题
- python创建一个集合_python如何创建一个集合
- 关于计算机图形标准化的论述 哪个是正确的,地大《计算机图形学(新)》在线作业 参考资料...
- 简述sqlite数据库的特点_为什么要用SQLITE?SQLITE数据库优点和缺点分析
- ipaddr库计算区间IP及CIDR的IP段
- 国家计算机科学进展,高等学校计算机一级学科教学改革与科学办学最新进展.pdf...
- php怎麼讲$字段的值截取第一个字,PHP截取中文字符串方法总结
- jsforeach异步的问题_js中forEach回调同异步题目
- linux用8m内存读取1g日志,检查 Linux 中内存使用状况的 8 条命令